How do I use standard Windows warning/error icons in my WPF app? How do I use standard Windows warning/error icons in my WPF app? wpf wpf

How do I use standard Windows warning/error icons in my WPF app?


There is a SystemIcons class, but it need adjustment for WPF needs (i.e. converting Icon to ImageSource).


The vast majority of developers out there don't know that Visual Studio comes with an Image Library. So here goes two links that highlight it:

About using Microsoft Visual Studio 2008 Image Library.


This is how I used a System icon in XAML:

xmlns:draw="clr-namespace:System.Drawing;assembly=System.Drawing"...<Image Source="{Binding Source={x:Static draw:SystemIcons.Warning},        Converter={StaticResource IconToImageSourceConverter},        Mode=OneWay}" />

I used this converter to turn an Icon to ImageSource:

public class IconToImageSourceConverter : IValueConverter{    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)    {        var icon = value as Icon;        if (icon == null)        {            Trace.TraceWarning("Attempted to convert {0} instead of Icon object in IconToImageSourceConverter", value);            return null;        }        ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(            icon.Handle,            Int32Rect.Empty,            BitmapSizeOptions.FromEmptyOptions());        return imageSource;    }    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)    {        throw new NotImplementedException();    }}