0
我有這樣一個CustomControl:如何在GridCell中使用ContextMenu?
<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>
在代碼隱藏IA有:
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
}
我從conrol在DataGrid電池用......當我點擊我的按鈕,我得到一個錯誤在這條線
b.ContextMenu.IsOpen = true;
「文本菜單」不能有邏輯或視覺父
我怎樣才能解決這個erorr
你爲什麼這樣做: b.ContextMenu.PlacementTarget = B ; b.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; ContextMenuService.SetPlacement(b,System.Windows.Controls.Primitives.PlacementMode.Bottom); – Amit 2012-02-02 09:22:15