첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ XmlDataProvider 엘리먼트의 XPath 속성을 사용해 XML 데이터를 사용하는 방법을 보여준다.

TestProject.zip
0.01MB

▶ 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="TestProject"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <StackPanel
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <StackPanel.Resources>
            <XmlDataProvider x:Key="XmlDataProviderKey"
                XPath="Inventory/Books">
                <x:XData>
                    <Inventory xmlns="">
                        <Books>
                            <Book
                                ISBN="0-7356-0562-9"
                                Stock="in"
                                Number="9">
                                <Title>XML in Action</Title>
                                <Summary>XML Web Technology</Summary>
                            </Book>
                            <Book
                                ISBN="0-7356-1370-2"
                                Stock="in"
                                Number="8">
                                <Title>Programming Microsoft Windows With C#</Title>
                                <Summary>C# Programming using the .NET Framework</Summary>
                            </Book>
                            <Book
                                ISBN="0-7356-1288-9"
                                Stock="out"
                                Number="7">
                                <Title>Inside C#</Title>
                                <Summary>C# Language Programming</Summary>
                            </Book>
                            <Book
                                ISBN="0-7356-1377-X"
                                Stock="in"
                                Number="5">
                                <Title>Introducing Microsoft .NET</Title>
                                <Summary>Overview of .NET Technology</Summary>
                            </Book>
                            <Book
                                ISBN="0-7356-1448-2"
                                Stock="out"
                                Number="4">
                                <Title>Microsoft C# Language Specifications</Title>
                                <Summary>The C# language definition</Summary>
                            </Book>
                        </Books>
                        <CDs>
                            <CD Stock="in" Number="3">
                                <Title>Classical Collection</Title>
                                <Summary>Classical Music</Summary>
                            </CD>
                            <CD Stock="out" Number="9">
                                <Title>Jazz Collection</Title>
                                <Summary>Jazz Music</Summary>
                            </CD>
                        </CDs>
                    </Inventory>
                </x:XData>
            </XmlDataProvider>
        </StackPanel.Resources>
        <TextBlock
            HorizontalAlignment="Center"
            Margin="10"
            FontSize="20"
            FontWeight="Bold">
            XML Data Source Sample
        </TextBlock>
        <ListBox
            Width="400"
            Height="300"
            Background="LightGray">
            <ListBox.ItemsSource>
                <Binding
                    XPath="*[@Stock='out'] | *[@Number>=8 or @Number=3]"
                    Source="{StaticResource XmlDataProviderKey}" />
            </ListBox.ItemsSource>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Foreground="Blue">
                        <TextBlock.Text>
                            <Binding XPath="Title" />
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>
</Window>
728x90
그리드형(광고전용)
Posted by icodebroker
,