< メモ: C# プログラミング ガイド | FontWeight のサンプル >

September 26, 2008

デザイナでは表示されるのですが・・・?

itemscontrolbinding.png

<Window x:Class="ItemsControlTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="京都市美術館">
    <Window.Resources>
        <XmlDataProvider x:Key="PropertyData">
            <x:XData>
                <properties>
                    <property caption="郵便番号:">606-8344</property>
                    <property caption="都道府県:">京都府</property>
                    <property caption="市区町村:">京都市左京区</property>
                    <property caption="字丁目:">岡崎円勝寺町</property>
                    <property caption="番地:">124</property>
                    <property caption="建物名以降:">岡崎公園内</property>
                    <property caption="電話番号:">075-771-4107</property>
                    <property caption="FAX番号:">075-761-0444</property>
                </properties>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>
    
    <ItemsControl Grid.IsSharedSizeScope="True" Margin="10" DataContext="{StaticResource PropertyData}" ItemsSource="{Binding XPath=/properties/property}">
    
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Vertical" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" SharedSizeGroup="PropCaption"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" Margin="5" Text="{Binding XPath=@caption}"/>
                    <TextBlock Grid.Column="1" Margin="5" Text="{Binding XPath=.}"/>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    
    </ItemsControl>
</Window>

実行すると真っ白なウインドウが表示されます。何で?

※ データソースが XmlDataProvider でなければ出るみたいですが…。

2008.09.29 追記
あーあーあほでしたー。
properties 要素に xmlns="" を追加すると表示されます。以前にもやらかしてるのにー。

トラックバック

このエントリーにトラックバック:
http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/2195

コメント

コメントする

※ コメントスパム対策のため、コメント本文はおはよう、こんにちわ、こんばんわのいずれかより始めるようにしてください。

name:
email:

※ 必要ですが、表示しません。

url:
情報を保存する ?