C# WPF条件上下文菜单选择器
我们在某个控件中有一个渲染的三维模型,我们希望在右键单击该模型时打开关联菜单。 但是,当右键单击背景时,我们希望打开一个不同的上下文菜单 现在,我已经实现了一个具有两个上下文菜单属性的控件,用于检查单击的像素是否为黑色(背景) 我们希望有另一个属性,它接受视图模型的属性/命令,该属性/命令获取x,y坐标并返回应该打开的上下文菜单的类型。C# WPF条件上下文菜单选择器,c#,wpf,mvvm,C#,Wpf,Mvvm,我们在某个控件中有一个渲染的三维模型,我们希望在右键单击该模型时打开关联菜单。 但是,当右键单击背景时,我们希望打开一个不同的上下文菜单 现在,我已经实现了一个具有两个上下文菜单属性的控件,用于检查单击的像素是否为黑色(背景) 我们希望有另一个属性,它接受视图模型的属性/命令,该属性/命令获取x,y坐标并返回应该打开的上下文菜单的类型。 有什么办法吗?以下是解决问题的多种方法之一-使用DataTemplateSelector 在XAML <Grid> <Grid.Con
有什么办法吗?以下是解决问题的多种方法之一-使用
DataTemplateSelector
在XAML
<Grid>
<Grid.ContextMenu>
<ContextMenu>
<ContextMenu.ItemContainerStyleSelector>
<!-- Nice I can have different ContainerStyles now depending on the context-->
</ContextMenu.ItemContainerStyleSelector>
<ContextMenu.ItemContainerTemplateSelector>
<!-- Nice I can have different Templates now for the content on the items depending on the context -->
</ContextMenu.ItemContainerTemplateSelector>
</ContextMenu>
</Grid.ContextMenu>
</Grid>
检查这个答案-这里有描述