How do i get an Image for the various MessageBoxImage(s) or MessageBoxIcon(s)

Solution 1:

SystemIcons is what I was looking for:

SystemIcons.Warning.ToBitmap();

Solution 2:

You can also include SystemIcons in your XAML as follows:

Include a converter (see code below) as a Resource, and an Image control in your XAML. This Image sample here shows the information icon.

     <Window.Resources>
        <Converters:SystemIconConverter x:Key="iconConverter"/>
     </Window.Resources>

     <Image Visibility="Visible"  
            Margin="10,10,0,1"
            Stretch="Uniform"
            MaxHeight="25"
            VerticalAlignment="Top"
            HorizontalAlignment="Left"
            Source="{Binding Converter={StaticResource iconConverter}, ConverterParameter=Information}"/>

Here is the implementation for the converter:

using System;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

namespace Converters
{
   [ValueConversion(typeof(string), typeof(BitmapSource))]
   public class SystemIconConverter : IValueConverter
   {
      public object Convert(object value, Type type, object parameter, CultureInfo culture)
      {
         Icon icon = (Icon)typeof(SystemIcons).GetProperty(parameter.ToString(), BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
         BitmapSource bs = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
         return bs;
      }

      public object ConvertBack(object value, Type type, object parameter, CultureInfo culture)
      {
         throw new NotSupportedException();
      }
   }
}