■ HierarchicalDataTemplate 엘리먼트 : XML 데이터를 사용해 트리 만들기
------------------------------------------------------------------------------------------------------------------------
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="HierarchicalDataTemplate 엘리먼트 : XML 데이터를 사용해 트리 만들기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <XmlDataProvider x:Key="XmlDataProviderKey" XPath="Authors"> <x:XData> <Authors xmlns=""> <Author Name="Jane Austen"> <BirthDate>1775</BirthDate> <DeathDate>1817</DeathDate> <Books> <Book Title="Sense and Sensibility"> <PubDate>1811</PubDate> </Book> <Book Title="Pride and Prejudice"> <PubDate>1813</PubDate> </Book> </Books> </Author> <Author Name="George Eliot"> <BirthDate>1819</BirthDate> <DeathDate>1880</DeathDate> <Books> <Book Title="Adam Bede"> <PubDate>1859</PubDate> </Book> </Books> <Books> <Book Title="Middlemarch"> <PubDate>1872</PubDate> </Book> </Books> </Author> <Author Name="Anthony Trollope"> <BirthDate>1815</BirthDate> <DeathDate>1882</DeathDate> <Books> <Book Title="Barchester Towers"> <PubDate>1857</PubDate> </Book> <Book Title="The Way We Live Now"> <PubDate>1875</PubDate> </Book> </Books> </Author> </Authors> </x:XData> </XmlDataProvider> <HierarchicalDataTemplate DataType="Author" ItemsSource="{Binding XPath=Books/Book}"> <StackPanel Margin="3" Orientation="Horizontal"> <TextBlock Text="{Binding XPath=@Name}" /> <TextBlock Text=" (" /> <TextBlock Text="{Binding XPath=BirthDate}" /> <TextBlock Text="-" /> <TextBlock Text="{Binding XPath=DeathDate}" /> <TextBlock Text=")" /> </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="Book"> <StackPanel Margin="3" Orientation="Horizontal"> <TextBlock Text="{Binding XPath=@Title}" /> <TextBlock Text=" (" /> <TextBlock Text="{Binding XPath=PubDate}" /> <TextBlock Text=")" /> </StackPanel> </HierarchicalDataTemplate> </Window.Resources> <Grid Margin="10"> <TreeView ItemsSource="{Binding Source={StaticResource XmlDataProviderKey}, XPath=Author}" /> </Grid> </Window>
|
------------------------------------------------------------------------------------------------------------------------
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Hyperlink 엘리먼트 사용하기 (0) | 2015.08.30 |
---|---|
[C#/WPF] EventTrigger 엘리먼트 : 마우스 왼쪽 버튼 DOWN 처리하기 (0) | 2015.08.28 |
[C#/WPF] ListBox 엘리먼트 : ItemContainerStyle 속성을 사용해 이벤트 설정하기 (0) | 2015.08.28 |
[C#/WPF] Interaction 엘리먼트 : Triggers 첨부 속성을 사용해 이벤트 처리하기 (0) | 2015.08.28 |
[C#/WPF] MVVM 패턴 사용하기 (0) | 2015.08.28 |
[C#/WPF] HierarchicalDataTemplate 엘리먼트 : XML 데이터를 사용해 트리 만들기 (0) | 2015.08.27 |
[C#/WPF] XmlDataProvider 엘리먼트 : Source 속성을 사용해 XML 데이터 사용하기 (0) | 2015.08.27 |
[C#/WPF] DatePicker 컨트롤 만들기 (0) | 2015.08.26 |
[C#/WPF] 템플리트 엘리먼트 찾기 (0) | 2015.08.26 |
[C#/WPF] ItemsPanelTemplate 엘리먼트 : ListBox 엘리먼트의 ItemsPanel 속성 설정하기 (0) | 2015.08.24 |
[C#/WPF] VirtualizingStackPanel 엘리먼트 사용하기 (0) | 2015.08.24 |
댓글을 달아 주세요