如何在 gridCell 中使用 ContextMenu?
我有一个像这样的 CustomControl:
<Button Name="b" Height="20" Click="b_Click" Content="operation" Width="60">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy"></MenuItem>
<MenuItem Header="cut"></MenuItem>
<MenuItem Header="delete"></MenuItem>
</ContextMenu>
</Button.ContextMenu>
</Button>
在 CodeBehind 中有:
if (b.ContextMenu != null && b.ContextMenu.IsOpen == false)
{
b.ContextMenu.PlacementTarget = b;
b.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
ContextMenuService.SetPlacement(b, System.Windows.Controls.Primitives.PlacementMode.Bottom);
b.ContextMenu.IsOpen = true;//I have error in this Line
}
我在 DataGrid 单元格中使用我的控件...当我单击按钮时,我在这一行中收到错误
b.ContextMenu.IsOpen = true;
“ContextMenu”不能有逻辑或视觉父级
我如何解决这个错误
I have a CustomControl like this:
<Button Name="b" Height="20" Click="b_Click" Content="operation" Width="60">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy"></MenuItem>
<MenuItem Header="cut"></MenuItem>
<MenuItem Header="delete"></MenuItem>
</ContextMenu>
</Button.ContextMenu>
</Button>
in CodeBehind ia have :
if (b.ContextMenu != null && b.ContextMenu.IsOpen == false)
{
b.ContextMenu.PlacementTarget = b;
b.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
ContextMenuService.SetPlacement(b, System.Windows.Controls.Primitives.PlacementMode.Bottom);
b.ContextMenu.IsOpen = true;//I have error in this Line
}
I use from my conrol in a DataGrid Cell ...when i click on my button i get an error in this line
b.ContextMenu.IsOpen = true;
"ContextMenu" cannot have logical or visual parent
how can i resolve this erorr
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个工作应用程序的示例,希望这能为您提供所需的线索......
A sample of working app, hope this gives you required clue...