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

728x90
반응형

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

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


TestProject.zip


Employees.xml

 

 

<Employees xmlns="">

    <Employee Name="Betty">

        <BirthDate>1970/08/31</BirthDate>

        <Face>IMAGE/Betty.png</Face>

        <LeftHanded>False</LeftHanded>

    </Employee>

    <Employee Name="Edgar">

        <BirthDate>1965/02/02</BirthDate>

        <Face>IMAGE/Edgar.png</Face>

        <LeftHanded>True</LeftHanded>

    </Employee>

    <Employee Name="Sally">

        <BirthDate>1980/07/12</BirthDate>

        <Face>IMAGE/Sally.png</Face>

        <LeftHanded>True</LeftHanded>

    </Employee>

    <Employee Name="Jim">

        <BirthDate>1975/06/15</BirthDate>

        <Face>IMAGE/Jim.png</Face>

        <LeftHanded>False</LeftHanded>

    </Employee>

    <Employee Name="Anne">

        <BirthDate>1975/04/07</BirthDate>

        <Face>IMAGE/Anne.png</Face>

        <LeftHanded>True</LeftHanded>

    </Employee>

    <Employee Name="John">

        <BirthDate>1955/12/02</BirthDate>

        <Face>IMAGE/John.png</Face>

        <LeftHanded>False</LeftHanded>

    </Employee>

</Employees>

 

 

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"

    xmlns:local="clr-namespace:TestProject"

    Width="800"

    Height="600"

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

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Window.Resources>

        <XmlDataProvider x:Key="EmployeeXmlDataProviderKey"

            Source="Employees.xml"

            XPath="Employees" />

    </Window.Resources>

    <Grid>

        <ListBox Name="listBox"

            HorizontalAlignment="Center"

            VerticalAlignment="Center"

            ItemsSource="{Binding Source={StaticResource EmployeeXmlDataProviderKey}, XPath=Employee}"

            SelectedValuePath="Face">

            <ListBox.ItemsPanel>

                <ItemsPanelTemplate>

                    <local:RadialPanel Orientation="ByHeight" />

                </ItemsPanelTemplate>

            </ListBox.ItemsPanel>

            <ListBox.ItemTemplate>

                <DataTemplate>

                    <DockPanel Margin="3">

                        <Image DockPanel.Dock="Right"

                            Stretch="None"

                            Source="{Binding XPath=Face}" />

                        <UniformGrid Rows="3"

                            VerticalAlignment="Center"

                            Margin="10">

                            <TextBlock

                                TextAlignment="Center"

                                Text="{Binding XPath=@Name}" />

                            <TextBlock

                                TextAlignment="Center"

                                FontSize="12pt"

                                Text="{Binding XPath=BirthDate}" />

                            <TextBlock Name="leftHandedTextBlock"

                                TextAlignment="Center"

                                Text="Right-Handed" />

                        </UniformGrid>

                    </DockPanel>

                    <DataTemplate.Triggers>

                        <DataTrigger Binding="{Binding XPath=LeftHanded}" Value="True">

                            <Setter

                                TargetName="leftHandedTextBlock"

                                Property="Text"

                                Value="Left-Handed" />

                        </DataTrigger>

                    </DataTemplate.Triggers>

                </DataTemplate>

            </ListBox.ItemTemplate>

        </ListBox>

        <Image

            HorizontalAlignment="Center"

            VerticalAlignment="Center"

            Stretch="None"

            Source="{Binding ElementName=listBox, Path=SelectedValue}" />

    </Grid>

</Window>

 

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

728x90
반응형
Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요