Answer the question
In order to leave comments, you need to log in
How to disable ContextMenu on child elements?
Is grid on it the collection kontrolov will settle down. I need to make the ContextMenu only work between items. There is such a sketch of the code, but it does not work. What am I doing wrong?
<Grid Background="Transparent">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Добавить"/>
<MenuItem Header="Удалить"/>
</ContextMenu>
</Grid.ContextMenu>
<StackPanel>
<Button Content="123" ContextMenuService.IsEnabled="False"/>
</StackPanel>
</Grid>
Answer the question
In order to leave comments, you need to log in
UserControl.xaml
<UserControl.Resources>
<ContextMenu x:Key="AmazingMenu">
<MenuItem Header="Item1"/>
<MenuItem Header="Item2"/>
</ContextMenu>
</UserControl.Resources>
<Grid x:Name="MegaGrid" Background="Transparent" MouseRightButtonDown="Grid_MouseRightButtonDown">
<!-- Some controls -->
</Grid>
private void Grid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
var control = e.OriginalSource as Grid;
if (control.Name.Equals("MegaGrid"))
{
MegaGrid.ContextMenu = FindResource("AmazingMenu") as ContextMenu;
}
else
{
MegaGrid.ContextMenu = null;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question