Images in .ico as DynamicResource

The situation looks like this:

  • I have many icons in the application, and they are used in several different sizes.
  • I use icons like DynamicResource, for example:

    <igRibbon:MenuTool (...) LargeImage="{DynamicResource IconAdd}" />

    <s:Item (...) Icon="{DynamicResource IconAdd}"/>

  • Some icons are in .xaml and some are in .png format

  • I add new icons, for example: <BitmapImage x:Key="IconAdd" UriSource="../Icons/IconAdd.png" />

Problem:
I would like to have .ico format icons that I can use as DynamicResource.

I need images in .ico because this file format allows you to have several different image sizes in a single file. The icons in .xaml are completely mutable, but they loaded a lot of time (because there really are a lot of them!).

Can I add a .ico file in quality DynamicResourceand add x:keyto it?

Even if I somehow add these .ico images, will they resize (depending on how much space they have)?

+3
source share
1 answer

Yes, .ico files can be added as DynamicResource(and, of course, because it is a resource it must have x:Key).

However, they will not automatically resize. Each size is extracted from .ico, like this, in which I make Imagefor each of the icon frames set to the exact frame size, and then add that Imageto StackPanel, calledimageStack

var iconUri = new URI( "pack://application:,,,/MyIcon.ico", UriKind.RelativeOrAbsolute );
var iconDecoder = new IconBitmapDecoder( iconUri,
    BitmapCreationOptions.None, BitmapCacheOption.Default );

foreach ( var frame in iconDecoder.Frames ) {
    var img = new Image(){
        Height = frame.PixelHeight,
        Width = frame.PixelWidth,
        Source = frame }
    imageStack.Children.Add( img );
}

.ico , , , Image / Image, Button , .

, , , :

  • BitmapFrames ResourceDictionary , 'MyIcon16', 'MyIcon32' ..
  • MarkupExtension IValueConverter, , , .
  • DynamicResource, .
  • . 32x32- Window ResourceDictionary 'MyIcon' 64x64 , Grid Window. , {DynamicResource MyIcon} Grid, 64x64 , 32x32 .
+3

All Articles