我在 App.xaml
中有一个 ContextMenu
,如下所示:
<ContextMenu x:Key="TreeContextMenuTest" ItemsSource="{Binding ContextMenu}">....
然后我有一个 ListView
,其项目在 Themes/Generic.xaml
中设置样式。它看起来像这样(我已经删除了不相关的东西。样式应用正确,我的问题只是关于如何附加上下文菜单)
<Style TargetType='{x:Type ListViewItem}'>
<Setter Property="ContextMenu" Value="{StaticResource TreeContextMenuTest}" />
</Style>
但是,我确实收到 DependencyProperty.UnsetValue is not a valid value for property ContextMenu
错误。有什么想法吗?
最佳答案
正如评论中提到的,使用DynamicResource
而不是StaticResource
-
<Setter Property="ContextMenu" Value="{DynamicResource TreeContextMenuTest}" />
关于c# - 将上下文菜单从 App.xaml 附加到 Setter 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16870235/