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

发布于 2024-08-23 15:53:25 字数 127 浏览 1 评论 0原文

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

在列表视图中选择项目我希望更新 TextBox Text 属性 按照listview数据绑定选中的item。 在 XAML 中可以吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如狂蝶 2024-08-30 15:53:25

当然...检查一下

<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(最有可能)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文