Trigger Property on another WPF control event
Suppose I have a ListView and TextBox and they are located in different containers in the same Window.
Selecting items in the listview I want the TextBox Text property to be updated in accordance with the listview data bound selected item. Is it possible in XAM开发者_如何学JAVAL?
Sure... Check this out
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<ListBox x:Name="lb">
<TextBlock Text="Hey"/>
<TextBlock Text="There"/>
</ListBox>
<TextBlock Text="{Binding SelectedItem.Text, ElementName=lb}"/>
</StackPanel>
</Page>
You can bind to SelectedItem. In this case, I'm cheating, because I know it's a TextBlock, but in the real world you'll have to write a DataTemplate (most likely).
精彩评论