■ XmlDataProvider 엘리먼트 : XML 데이터 사용하기

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

Employees.xml

 

빌드 작업resource로 설정한다.

 

<Employees xmlns="">

    <Employee Name="Betty">

        <BirthDate>8/31/1970</BirthDate>

        <Face>Betty.png</Face>

        <LeftHanded>False</LeftHanded>

    </Employee>

    <Employee Name="Edgar">

        <BirthDate>2/2/1965</BirthDate>

        <Face>Edgar.png</Face>

        <LeftHanded>True</LeftHanded>

    </Employee>

    <Employee Name="Sally">

        <BirthDate>7/12/1980</BirthDate>

        <Face>Sally.png</Face>

        <LeftHanded>True</LeftHanded>

    </Employee>

    <Employee Name="Jim">

        <BirthDate>6/15/1975</BirthDate>

        <Face>Jim.png</Face>

        <LeftHanded>False</LeftHanded>

    </Employee>

    <Employee Name="Anne">

        <BirthDate>4/7/1975</BirthDate>

        <Face>Anne.png</Face>

        <LeftHanded>True</LeftHanded>

    </Employee>

    <Employee Name="John">

        <BirthDate>12/2/1955</BirthDate>

        <Face>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:src="clr-namespace:TestProject"

    Title="Employee Wheel"

    SizeToContent="WidthAndHeight">

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

                    <src:RadialPanel Orientation="ByHeight" />

                </ItemsPanelTemplate>

            </ListBox.ItemsPanel>

            <ListBox.ItemTemplate>

                <DataTemplate>

                    <DockPanel Margin="3">

                        <Image

                            DockPanel.Dock="Right"

                            Stretch="None"

                            Source="{Binding XPath=Face}" /> <!-- Employee 노드 Face 하위 노드 지정 -->

                        <UniformGrid Rows="3"

                            VerticalAlignment="Center"

                            Margin="12">

                            <TextBlock

                                TextAlignment="Center"

                                FontSize="16pt"

                                Text="{Binding XPath=@Name}" /> <!-- Employee 노드 Name 속성 지정시 @를 추가한다. -->

                            <TextBlock

                                TextAlignment="Center"

                                FontSize="12pt"

                                Text="{Binding XPath=BirthDate}" /> <!-- Employee 노드 BirthDate 하위 노드 지정 -->

                            <TextBlock

                                Name="leftHandedTextBlock"

                                TextAlignment="Center"

                                FontSize="12pt"

                                Text="Right-Handed" />

                        </UniformGrid>

                    </DockPanel>

                    <DataTemplate.Triggers>

                        <DataTrigger Binding="{Binding XPath=LeftHanded}" Value="True"> <!-- Employee 노드 LeftHanded 하위 노드 지정 -->

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

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

※ RadionPanel 엘리먼트 : "Panel 클래스 : RadialPanel 클래스 만들기" 참조

Posted by 사용자 icodebroker

댓글을 달아 주세요