无法打开上下文菜单

时间:2013-12-22 21:14:51

标签: c# wpf contextmenu

我无法通过人民币点击打开我的上下文菜单。但如果我点击人民币按下LMB上下文菜单显示。我不知道它是什么。如果你向我解释这种情况,我将非常感激。

这是我的代码:

ContextMenu NodeContextMenu = new ContextMenu();
MenuItem info = new MenuItem();
info.Header = "Info";
info.Click += info_Click;
MenuItem properties = new MenuItem();
properties.Header = "Properties";
properties.Click += properties_Click;
NodeContextMenu.Items.Add(info);
NodeContextMenu.Items.Add(properties);

Label newLabel = new Label();
newLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
newLabel.VerticalAlignment = System.Windows.VerticalAlignment.Center;
newLabel.Content = newNode.number;
newLabel.FontFamily = new FontFamily("Bauhaus 93");
newLabel.FontSize = 30;
newLabel.Foreground = Brushes.Black;
newLabel.Uid = newNode.number + "label";
newLabel.Tag = newNode.number.ToString();
newLabel.Drop += Ellipse_Drop;
newLabel.MouseDown += Ellipse_MouseDown;
newLabel.ContextMenu = NodeContextMenu;

Ellipse newEllipse = new Ellipse();
newEllipse.Height = nodeRadius * 2;
newEllipse.Width = nodeRadius * 2;
newEllipse.Fill = Brushes.White;
newEllipse.Stroke = Brushes.Black;
newEllipse.StrokeThickness = 3;
newEllipse.Uid = newNode.number + "ellipse";
newEllipse.Tag = newNode.number.ToString();
newEllipse.Drop += Ellipse_Drop;
newEllipse.MouseDown += Ellipse_MouseDown;
newEllipse.ContextMenu = NodeContextMenu;

Grid newGrid = new Grid();
newGrid.SetValue(MarginProperty, new Thickness(newNode.centerCoords.X - nodeRadius, newNode.centerCoords.Y - nodeRadius, 0, 0));
newGrid.Uid = newNode.number + "grid";
newGrid.Tag = newNode.number.ToString();

newGrid.Children.Add(newEllipse);
newGrid.Children.Add(newLabel);

MainCanvas.Children.Add(newGrid);

1 个答案:

答案 0 :(得分:0)

我弄清楚问题是什么。我的Drag& Drop事件阻止了上下文菜单事件的处理。