开发者

WPF: Highlight TreeView Item Displaying Context Meu

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 开发者_如何学GoI highlight a given item on a context menu display event?

Thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜