繁体   English   中英

在另一个WPF控件事件上触发属性

[英]Trigger Property on another WPF control event

假设我有一个ListView和TextBox,它们位于同一Window的不同容器中。

在列表视图中选择项目我希望根据列表视图数据绑定的选定项目来更新TextBox Text属性。 XAML中可能吗?

好吧...检查一下

<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>

您可以绑定到SelectedItem。 在这种情况下,我在作弊,因为我知道它是一个TextBlock,但在现实世界中,您将不得不编写DataTemplate(最有可能)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM