So I have a MenuItem (within a ContextMenu, if it really makes a difference, don't think it does). I want to display an icon within the MenuItem using the MenuItem.Icon property. Here is XAML code that does this:
<MenuItem Header="MenuItem1">
<MenuItem.Icon>
<Image Source="[pathtoimage]"/>
</MenuItem.Icon>
</MenuItem>
This works. But what if I want to specify the size of the icon with Height and Width ? Search on the web reveals that it should be 32, some say it should be 20. 20 works the best for me, but I don't want to hardcode 20. I want to set it to the same height as the MenuItem, given the fact that on a different resolution the actual height might be different. So, I tried the following:
<MenuItem x:Name="menuItem1" Header="MenuItem1">
<MenuItem.Icon>
<Image Source="[pathtoimage]"
Height="{Binding Path=ActualHeight, ElementName=menuItem1}"
Width="{Binding Path=ActualHeight, ElementName=menuItem1}"
</MenuItem.Icon>
</MenuItem>
You would think that it should work, but it didn't. The question is why ? I am able to get my desired appearance if I set both Width and Height to 20. But if the system font size gets changed, then 20x20 won't be ideal anymore. It would be ideal to do this in the XAML, because I am sure there are a lot of ways of handling this in the code-behind.