0

I have made a custom error message box for my project. In the View for this, I have an image which should be used for message type (Error, Info, Warn, etc.) which Windows already has built-in images for. Is there a way I can use these images via setting the source property in XAML programatically?

(I have been using this guide for making the box, if it helps)

Harry Adams
  • 423
  • 5
  • 16
  • If you chose to copy the icons into a folder for your use you may use the program "IconsExtract" by NirSoft or similar, an the directories the icons are stored are listed on this site: https://www.digitalcitizen.life/where-find-most-windows-10s-native-icons the icons are usually stored in dll or exe files for example %systemroot%\system32\imageres.dll. Good luck! – Issung Oct 31 '19 at 12:25

1 Answers1

1

I believe this works, if you want to do it the nasty way (it's the only way I know to get the "WinForms style" images):

var sii = new SHSTOCKICONINFO();
sii.cbSize = (UInt32)Marshal.SizeOf(typeof(SHSTOCKICONINFO));    
Marshal.ThrowExceptionForHR(SHGetStockIconInfo(SHSTOCKICONID.SIID_WARNING, SHGSI.SHGSI_ICON, ref sii));
ImageSource = Icon.FromHandle(sii.hIcon).ToImageSource();

Note: I chose not to use this, and instead just included images in my resources to use as I needed them.

DonBoitnott
  • 10,787
  • 6
  • 49
  • 68
  • Do you happen to know where the typical Windows images would be located, to make a copy of? – Harry Adams Oct 31 '19 at 12:22
  • I do not. There are system DLLs from which you can extract them, but it's all a bit tedious. Better off finding something in a library already, or take the advice on the duplicate post(s). – DonBoitnott Oct 31 '19 at 12:23
  • Aye you answered before the duplicate post appeared. Thank you for the time, but will likely use the duplicate's – Harry Adams Oct 31 '19 at 12:25