开发者

How to bind textbox to listbox content when listbox is bound to another source?

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" 
                       Te开发者_JAVA技巧xt="{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


Your data is an XmlAttriute, bind to InnerText

Text="{Binding ElementName=listBox1, Path=SelectedItem.InnerText, Mode=OneWay}"


Replace Path= SelectedItem.Content by Path = SelectedItem.Value

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜