Disappearing Icons in WPF

I want to use some icons from VS2008ImageLibrary / Actions / pngformat in my WPF application to get a more visual look of Visual Studio - like the "Insert Standard Elements" command in WinForms.
I added images as resources and referenced them in my xaml file:

<DockPanel.Resources>
        <Image x:Key="NewIcon" Source="Toolbar Images/NewDocumentHS.png" Height="16" Width="16"/>
</DockPanel.Resources>

And then I added an image to the menu and toolbar

<MenuItem Command="ApplicationCommands.New" Icon="{StaticResource NewIcon}"/>
<!-- ... -->
<Button Command="ApplicationCommands.Save"><StaticResourceExtension ResourceKey="SaveIcon"/></Button>

However, when I open the menu, the icon disappears from the toolbar, as if the button had never been there. I read elsewhere that this happens due to the lack of .NET support for Vista Icons / PNG compressed, but I'm not sure if this is exactly the same problem. My attempts to get around this by changing the formats failed or yielded suboptimal results (for example, loss of transparency). Does anyone know how best to do this?

Edit: For other people having this problem, creating duplicate entries with different keys in the <DockPanel.Resources> tag for each link seems quite functional, although I would have thought that the images might disappear again if they need to be reloaded for any reason.

+1
source share
2

, Button:

    <DockPanel.Resources>
        <Image x:Key="NewIconForMenu" Source="Toolbar Images/NewDocumentHS.png" Height="16" Width="16"/>
<Image x:Key="NewIconForButton" Source="Toolbar Images/NewDocumentHS.png" Height="16" Width="16"/>
</DockPanel.Resources>

, Image, Image. MenuItem Button, Icon Content, . .

, NewIcon, .

, MenuItem , , , Image Button ( ), .

, . x: Shared = "false" declaraiton . wpf.

+3

, .

+1

Source: https://habr.com/ru/post/1705493/


All Articles