pfinferno
pfinferno

Reputation: 1953

MenuItems' Icon size changes on different systems

I have a WPF UserControl hosted inside of a WinForms application. This UserControl has a ContentControl which has a ContextMenu. The ContextMenu has a few MenuItems, all of which have their Icon property set to a .ico.

For whatever reason, the icons become massive on different systems. I've tested them on a Windows 10 and Windows 7 machine and they are fine, but other win10/win7 machines they are huge.

The actual .ico files range from 32x32 bit to 256x256.

Here's how they look normally: enter image description here

Here's how they look on certain machines: enter image description here

Here's the .xaml:

<UserControl x:Class="TestUC.MainWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="737.239" Width="1455.446"
    <Grid>
        <ContentControl>
            <ContentControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Pan">
                        <MenuItem.Icon>
                            <Image Source="Images/panHand.ico" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Zoom In">
                        <MenuItem.Icon>
                            <Image Source="Images/zoom_In.ico" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Zoom Out">
                        <MenuItem.Icon>
                            <Image Source="Images/zoom_Out.ico" />
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </ContentControl.ContextMenu>
        </ContentControl>
    </Grid>
</UserControl>

I can go ahead and manually set the Height and Width, but I would love to know what causes this.

Upvotes: 0

Views: 277

Answers (1)

Andy
Andy

Reputation: 12276

It's my understanding the user setting for icon size will influence this particular scenario.

They pick big icons then windows will prefer the big version of the ico.

I'm not sure about that because I never risk default sizes for Image.

In any event, it's picking 256x256 and you gave it no size so it decides that image is 256x256.

IMO.

It's a bad idea to use ico or any bitmap file for this stuff in a wpf app.

You're best using vector graphics.

A Path for simple iconography.

With a menu, that does also mean some re-templating or replacing the header.

But you can then have consistent scaleable iconography across your application.

Using very lightweight geometries in a resource dictionary.

Upvotes: 1

Related Questions