첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ XmlDataProvider 엘리먼트 : Source 속성을 사용해 XML 데이터 사용하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


Customer.xml

 

 

<?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

 

 

<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>

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요