Reputation: 3
I have a simple code and I’m trying to bind a TextBlock’s Text property to the ListBox but it doesn’t work! I was trying to follow the instructions in this site http://msdn.microsoft.com/en-us/magazine/cc163299.aspx Below is my code:
<StackPanel>
<StackPanel.Resources>
<XmlDataProvider x:Key="MoreColors" XPath="Colors">
<x:XData>
<Colors xmlns="">
<color name="Green"/>
<color name="Blue"/>
</Colors>
</x:XData>
</XmlDataProvider>
</StackPanel.Resources>
<TextBlock Height="23" Name="textBlock1" TextAlignment="Center"
Text="{Binding ElementName=listBox1, Path= SelectedItem.Content, Mode=OneWay}"
Background="{Binding Path=Text, RelativeSource={RelativeSource Self}}" Width="119" />
<ListBox x:Name="listBox1" Width="248" Height="56"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource MoreColors},
XPath=color/@name}">
</ListBox>
</StackPanel>
I wonder how I can fix this problem. Thanks Rich
Upvotes: 0
Views: 2065
Reputation: 184296
Your data is an XmlAttriute, bind to InnerText
Text="{Binding ElementName=listBox1, Path=SelectedItem.InnerText, Mode=OneWay}"
Upvotes: 1