图片's菜单在XP中左键不打开

本文关键字:XP 菜单 图片 | 更新日期: 2023-09-27 17:54:58

我试图有一个图像(在WPF),显示一个菜单时,鼠标左键单击。它在7中工作得很好,然而,当我尝试在XP中使用它时,它只在右键单击时显示?什么好主意吗?

以下是XAML代码:
<Image x:Name="buttonHelp" Width="32" Height="32"  Margin="0,0,5,0" Source="/Little Registry Optimizer;component/Resources/Help.png" MouseEnter="button_MouseEnter" MouseLeave="button_MouseLeave" MouseDown="buttonHelp_MouseLeftButtonDown" />

下面是c#代码:

private void button_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
    this.Cursor = Cursors.Hand;
}
private void button_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
    this.Cursor = Cursors.Arrow;
}
private void buttonHelp_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    ContextMenu contextMenu = new ContextMenu();
    this.buttonHelp.ContextMenu = contextMenu;
    contextMenu.Items.Add(CreateMenuItem(Properties.Resources.Help, "Help"));
    contextMenu.Items.Add(new Separator());
    contextMenu.Items.Add(CreateMenuItem(Properties.Resources.internet, "Visit Website"));
    contextMenu.Items.Add(CreateMenuItem(Properties.Resources.update, "Check for updates"));
    contextMenu.Items.Add(new Separator());
    contextMenu.Items.Add(CreateMenuItem(Properties.Resources.optimizer, "About..."));
    contextMenu.PlacementTarget = (System.Windows.UIElement)sender;
    contextMenu.IsOpen = true;
    contextMenu.StaysOpen = true;
}

谢谢!

图片's菜单在XP中左键不打开

只是让你知道我已经解决了这个问题,通过使用一个按钮而不是一个图像。您仍然可以将按钮设置为将Image作为其内容。然后,您可以简单地订阅按钮点击事件(我知道这将在XP或其他任何东西上工作)。

我做的另一件事是用下面的代码设置上下文菜单的位置:
buttonHelp.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
ContextMenuService.SetPlacement(buttonHelp, System.Windows.Controls.Primitives.PlacementMode.Bottom);