如何将 IsSelected 属性绑定到文本块

发布于 2024-12-03 03:52:54 字数 107 浏览 5 评论 0原文

我的树视图填充了文本块项目。 如果用户单击文本块,我想在模型中设置一个名为“isSelected”的属性。 但是:文本块没有属性 IsSelected。 我怎样才能实现这个? 从文本块派生并添加属性?

my treeview is populated with textblock items.
If a user clicks on a textblock, i want to set a property in my model called "isSelected".
But : the textblock have no Property IsSelected.
How can i Implement this ?
Derive from textblock and add a Property ?

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

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

发布评论

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

评论(1

怕倦 2024-12-10 03:52:54

您必须使用 TreeViewItem.IsSelected 财产。您必须为树视图的所有项目指定自定义样式。

<TreeView>
    <TreeView.Resources>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected}"/>
        </Style>
    </TreeView.Resources>
</TreeView>

You have to use the TreeViewItem.IsSelected property. You will have to specify the custom style for all items of the tree view.

<TreeView>
    <TreeView.Resources>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected}"/>
        </Style>
    </TreeView.Resources>
</TreeView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文