Sometimes you would like to use a standard Windows system icon, such as error, warning, question etc. in your WPF program. The main reason is usually consistent look with the rest of the system. While you could have extracted the desired icon from one of the system resource files, there is a much better technique for doing it. First, add a reference to System.Drawing to your project. Then you can use this sample code to get the desired icon quickly:

var error = System.Drawing.SystemIcons.Error;
            // You can adjust the parameters of BitmapSizeOptions to suite your specific needs
            var image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(error.Handle, 
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            // icon has been declared as Image
            icon.Source = image;

Further reading - MSDN library .

Tags: computers
Categories: None |

0 comments have been posted.

Your email: we will send you a confirmation link to this address to confirm your identity and to prevent robot posting
Get in touch
»...«
Follow updates

Join our social networks and RSS feed to keep up to date with latest news and publications