WPF:突出显示显示上下文菜单的 TreeView 项目

发布于 2024-10-10 20:50:00 字数 230 浏览 0 评论 0原文

我正在使用 TreeView 进行过滤器选择。

TreeView 上的不同类别启动不同的过滤器,运行时间可能长达 3 秒。

每个类别都有自己的上下文菜单,您可以在其中重命名、删除等。

我想让用户在他右键单击的项目上看到它。一种方法是在右键单击事件上选择项目。但这会导致菜单加载缓慢,因为它运行相关的过滤器。

那么,如何在上下文菜单显示事件中突出显示给定项目?

谢谢

I am using a TreeView for filters selection.

Different categories on the TreeView start different filters, that may take up to 3 seconds to run.

Each category has it's own context menu, where u can rename, delete, etc.

I want to make it visible to the user on which item he rightclicked. On way would be to select the item on the rightclick event. But this causes the menu to load slowly, since it runs the related filter.

So, how can I highlight a given item on a context menu display event?

Thanks

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

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

发布评论

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

评论(1

情愿 2024-10-17 20:50:00

触发绑定到上下文菜单的 IsOpen 属性的样式设置器。我在项目上使用样式中的 DataTrigger 来实现此操作,如下所示:

<Style TargetType="{x:Type TreeViewItem}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding ContextMenu.IsOpen, RelativeSource={RelativeSource Self}}" Value="True">
            <Setter Property="Foreground" Value="Red"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

显然,您可以选择比将文本变成红色更合适的操作(例如可能使背景看起来被选中),但这是一般的想法。

Trigger a style setter bound to the context menu's IsOpen property. I got this to work using a DataTrigger in a Style on the item like this:

<Style TargetType="{x:Type TreeViewItem}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding ContextMenu.IsOpen, RelativeSource={RelativeSource Self}}" Value="True">
            <Setter Property="Foreground" Value="Red"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

Obviously you can choose something more appropriate to do than turning the text red (like maybe making the background look selected), but that's the general idea.

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