■ XmlDataProvider 엘리먼트의 Source 속성을 사용해 XML 데이터를 로드하는 방법을 보여준다.
▶ Customer.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?xml version="1.0" encoding="utf-8"?> <Data> <Customer FirstName="Orlando" LastName="Gee" /> <Customer FirstName="Keith" LastName="Harris" /> <Customer FirstName="Donna" LastName="Carreras" /> <Customer FirstName="Janet" LastName="Gates" /> <Customer FirstName="Lucy" LastName="Harrington" /> <Customer FirstName="Rosmarie" LastName="Carroll" /> <Customer FirstName="Dominic" LastName="Gash" /> <Customer FirstName="Kathleen" LastName="Garza" /> <Customer FirstName="Katherine" LastName="Harding" /> <Customer FirstName="Johnny" LastName="Caprio" /> ... <Customer FirstName="Kara" LastName="Vanderlinden" /> <Customer FirstName="Nieves" LastName="Vargas" /> <Customer FirstName="Gary" LastName="Vargas" /> <Customer FirstName="Ranjit" LastName="Varkey Chudukatil" /> <Customer FirstName="Patricia" LastName="Vasquez" /> <Customer FirstName="Raja" LastName="Venugopal" /> <Customer FirstName="Dora" LastName="Verdad" /> <Customer FirstName="Wanda" LastName="Vernon" /> <Customer FirstName="Robert" LastName="Vessa" /> <Customer FirstName="Caroline" LastName="Vicknair" /> </Data> |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<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="XmlDataProvider 엘리먼트 : Source 속성을 사용해 XML 데이터 사용하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <XmlDataProvider x:Key="CustomerXmlDataProviderKey" XPath="Data" Source="Customer.xml" /> </Window.Resources> <Grid Margin="10"> <DataGrid AutoGenerateColumns="False" IsReadOnly="True" ItemsSource="{Binding Source={StaticResource CustomerXmlDataProviderKey}, XPath=Customer}"> <DataGrid.Columns> <DataGridTextColumn Header="이름" FontStyle="Italic" Binding="{Binding XPath=@FirstName}" /> <DataGridTextColumn Header="성" FontWeight="Bold" Binding="{Binding XPath=@LastName}" /> </DataGrid.Columns> </DataGrid> </Grid> </Window> |