Image's menu doesnt open on left click in XP
I am trying to have a image (in WPF) that shows a menu when the mouse is left clicked. It works fine in 7, however, when I try to use it in XP it only shows up when its right clicked? any ideas?
Here is the XAML Code:
<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" />
Here is the C# Code:
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;
}
Thanks!
Just so you know I have solved this problem by using a button instead of an Image. You can still set the button to have the Image as its content. Then you can simply subscribe to the Buttons Click event (which I know will work on XP or anything else).
One other thing I did was set the placement of the Context Menu with this code:
buttonHelp.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
ContextMenuService.SetPlacement(buttonHelp, System.Windows.Controls.Primitives.PlacementMode.Bottom);
精彩评论