Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an ImageSource in XAML to PackIcon Kind?

I'm trying to put together a ribbon control and I like to use the icons in the IconPack of the MaterialDesign WPF Toolkit. Is there a way that I can get to the icon image itself?

For example: Using a Grid Icon, the code is <materialDesign:PackIcon Kind="Grid" />.

How do I assign that icon to the ImageSource?

like image 290
Steve Brother Avatar asked Oct 19 '25 16:10

Steve Brother


1 Answers

You could use a custom converter as suggested here: https://github.com/MahApps/MahApps.Metro.IconPacks/issues/39.

<Window.Resources>
    <local:PackIconImageSourceConverter x:Key="PackIconImageSourceConverter" />
</Window.Resources>
...
<Image Source="{Binding Source={x:Static iconPacks:PackIconMaterialKind.Grid}, Converter={StaticResource PackIconImageSourceConverter}}" 
       Stretch="None" />

You will find the code for the converter class here: https://gist.github.com/PhyxionNL/160a6f04e6083016d4b2a3aed3c4fe71

EDIT: This was incorporated into MahApps.Metro as PackIconKindToImageConverterBase.

like image 185
mm8 Avatar answered Oct 21 '25 05:10

mm8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!