Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the icon for image contextMenu items

When I click image it displayed the menu but icon's are not displayed. I tried in two ways:

  1. One is I resized the icon that's not working
  2. Second one is I set the path using icon property that's not working.

What's the way to set the icon for context menu items??

Xaml:

<Image Height="20" Width="20" Source="/CitiCall.WinClient;component/Images/user_icon.png" MouseDown="image1_MouseDown"  Margin="0,0,4,6" HorizontalAlignment="Right"  Name="image1" Stretch="Fill" VerticalAlignment="Top">               
    <Image.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Reset password" Icon="/CitiCall.WinClient;component/Images/reset.png"/>
                <!--<MenuItem.Icon>
                    <Image Source="/CitiCall.WinClient;component/Images/reset.png" ></Image>
                </MenuItem.Icon>
            </MenuItem>-->
            <MenuItem Header="Edit Profile"/>
            <MenuItem Header="Settings"/>
            <MenuItem Header="About us"/>
        </ContextMenu>
    </Image.ContextMenu>
</Image>

Xamal.cs:

private void image1_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    if (e.ChangedButton == MouseButton.Left)
    {
        Image image = sender as Image;
        ContextMenu contextMenu = image.ContextMenu;                
        contextMenu.PlacementTarget = image;
        contextMenu.IsOpen = true;
    }
}
like image 592
Arul karnan Avatar asked Oct 12 '15 14:10

Arul karnan


1 Answers

Actually it should work if you write :

<MenuItem.Icon>
  <Image Source="Images/reset.png" ></Image>
</MenuItem.Icon>

Just take care of right clicking to the properties of the images in your project, set it as Content, and Copy if newer.

Have a look at : WPF image resources

Regards

like image 86
Emmanuel DURIN Avatar answered Nov 15 '22 00:11

Emmanuel DURIN