У меня есть кнопка, которая имеет контекстное меню. Это контекстное меню открывается по щелчку левой кнопкой мыши. Проблема в том, что контекстное меню закрывается при нажатии кнопки правой кнопкой мыши. Я хочу отключить щелчок правой кнопкой мыши на кнопке.
private void NotificationBtn_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Right)
{
e.Handled = true;
return;
}
if (e.ChangedButton == MouseButton.Left)
{
(sender as Button).ContextMenu.IsEnabled = true;
(sender as Button).ContextMenu.PlacementTarget = (sender as Button);
(sender as Button).ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
(sender as Button).ContextMenu.IsOpen = true;
}
}
private void NotificationBtn_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Right)
{
e.Handled = true;
}
}
Как сохранить это контекстное меню открытым при нажатии кнопки правой кнопкой мыши?