I have several icons which are declared in Window.Resources. They show up fine the first time they need to appear (eg: a Menu is clicked, the MenuItem icon works), but after another Menu (eg: a context menu) is shown, the original icon disappears and does not return. It's as though the last element which used the icon for the first time gets to keep it.
<Window.Resources>
<Image x:Key="Chart_16"
Source="pack://application:,,,/Resources/images/chart_16.png" />
...
<Window.Resources>
<MenuItem Header="Summary"
Command="loc:AppCommands.ShowSummary"
Icon="{StaticResource Chart_16}" />
I've tried saving it as a 24bit PNG, an interlaced 24bit PNG and an 8bit PNG but the same thing happens. It's not just one, every icon which is used in more than one place behaves this way.
That's because your resource is an Image
, which is a Control
. Control
s can only have one parent so it's effectively being re-parented in each MenuItem
on the fly.
Your options are:
Image
and instead use ImageSource
or even a string
containing the URI of the image.x:Shared
XAML attribute. This will create multiple Image
controls as needed.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With