Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

XMLを静的にバインドする

アプリ実行


ソースコード

App.xaml
<Application x:Class="WpfApplication6.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
</Application>
MainWindow.xaml
<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <XmlDataProvider x:Key="dataSource">
            <x:XData>
                <Company xmlns="">
                    <Section Manager="山田太郎" SectionName="総務部" />
                    <Section Manager="山田太郎" SectionName="経理部" />
                    <Section Manager="渡辺次郎" SectionName="人事部" />
                </Company>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>
    <ListBox ItemsSource="{Binding XPath=/Company/Section/@SectionName, Source={StaticResource dataSource}}" />
</Window>