ListBox Bound DataTemplate Shows Up Blank
-
Folks, I've been staring at this for hours and am missing something simple. Items in the first list box show up fine. However, I need to use a DataTemplate because the items in my real app are much more complex. Three items show up in the second listbox but they are all blank. Any ideas?
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1"> <Page.Resources> <XmlDataProvider x:Key="SetProvider" XPath="SetNums"> <x:XData> <SetNums xmlns=""> <SetNum>0</SetNum> <SetNum>1</SetNum> <SetNum>2</SetNum> </SetNums> </x:XData> </XmlDataProvider> <DataTemplate x:Key="SetTemplate"> <Label Content="{Binding XPath=SetNum}"/> </DataTemplate> </Page.Resources> <StackPanel Orientation="Horizontal"> <ListBox x:Name="lstWorks" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> <ListBox x:Name="lstDoesNotWorkWhyDoItemsAppearBlank" ItemTemplate="{StaticResource SetTemplate}" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> </StackPanel> </Page>
Sincerely, -Ron
-
Folks, I've been staring at this for hours and am missing something simple. Items in the first list box show up fine. However, I need to use a DataTemplate because the items in my real app are much more complex. Three items show up in the second listbox but they are all blank. Any ideas?
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1"> <Page.Resources> <XmlDataProvider x:Key="SetProvider" XPath="SetNums"> <x:XData> <SetNums xmlns=""> <SetNum>0</SetNum> <SetNum>1</SetNum> <SetNum>2</SetNum> </SetNums> </x:XData> </XmlDataProvider> <DataTemplate x:Key="SetTemplate"> <Label Content="{Binding XPath=SetNum}"/> </DataTemplate> </Page.Resources> <StackPanel Orientation="Horizontal"> <ListBox x:Name="lstWorks" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> <ListBox x:Name="lstDoesNotWorkWhyDoItemsAppearBlank" ItemTemplate="{StaticResource SetTemplate}" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> </StackPanel> </Page>
Sincerely, -Ron
Ron - change this line:
<Label Content="{Binding XPath=SetNum}"/>
to
<Label Content="{Binding}"/>
That ought to do it.
Deja View - the feeling that you've seen this post before.
-
Ron - change this line:
<Label Content="{Binding XPath=SetNum}"/>
to
<Label Content="{Binding}"/>
That ought to do it.
Deja View - the feeling that you've seen this post before.
-
Thanks Pete. That did it. Upon reflection, the binding already included XPath so it did not need to be in the data template.
Sincerely, -Ron
:-D I know - it's always something simple like that, that keeps you hunting about for hours.
Deja View - the feeling that you've seen this post before.