gpt4 book ai didi

wpf - 如何设置绑定(bind)项目的 ContextMenu?

转载 作者:行者123 更新时间:2023-12-04 15:16:33 24 4
gpt4 key购买 nike

我正在努力实现以下目标:

<Style TargetType="ListBoxItem">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Name="mnuEdit" Header="_Edit" Click="MenuItem_Click" />
</ContextMenu>
</Setter.Value>
</Setter>
<Style>

但它会引发以下异常:
Cannot add content of type 'System.Windows.Controls.ContextMenu'
to an object of type 'System.Object'.
Error at object 'System.Windows.Controls.ContextMenu'
in markup file blah blah blah

最佳答案

试试这个:

<ContextMenu x:Key="contextMenu">
<MenuItem Name="mnuEdit" Header="_Edit" Click="MenuItem_Click" />
</ContextMenu>

<Style TargetType="ListBoxItem">
<Setter Property="ContextMenu" Value="{DynamicResource contextMenu}" />
</Style>

关于wpf - 如何设置绑定(bind)项目的 ContextMenu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1397497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com