简体   繁体   中英

Convert icon file to XAML

I have several windows icons that I would like to use in an existing WPF application.

The application uses XAML DrawingImages that are in a ResourceDictionary.

Is there a way to convert my windows icon files to a XAML DrawingImage?

You could directly create a BitmapImage from an icon file, like

<Window.Resources>
    <BitmapImage x:Key="Icon1" UriSource="Icons/Icon1.ico" />
</Window.Resources>

and eg use that as the Source of an Image control

<Image Source="{StaticResource Icon1}" />

or as well for a DrawingImage, like

<DrawingImage>
    <DrawingImage.Drawing>
        <ImageDrawing ImageSource="{StaticResource Icon1}"/>
    </DrawingImage.Drawing>
</DrawingImage>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM