Reputation: 345
I am trying to assign an icon to the Window.Icon in codebehind. I know its easy to do it in xaml but I am using the same custom window template to different applications which obviously have different icons. I added the .ico file to the same project where I am trying to assign the icon. I tried this:
IconBitmapDecoder ibd = new IconBitmapDecoder(new Uri(@"pack://application:,,,/TEST_MLT.ico", UriKind.Absolute),
BitmapCreateOptions.None, BitmapCacheOption.Default);
m_windows[p_WindowID].Window.Icon = ibd.Frames[0];
It threw cannot find resource TEST_MLT.ico exception. Please some light on how to do it. Thanks.
Upvotes: 0
Views: 1442
Reputation: 1773
It works for me by setting the icon using System.Windows.Media.Imaging.BitmapImage. This solution works if your icon is located at the root directory. If you have it buried in another folder somewhere, you will need to add that to the Uri.
For example, I keep my icons in Images/32x32/MyIcon.png, so I would need to update the Uri to that path.
this.Icon = new System.Windows.Media.Imaging.BitmapImage(
new Uri(@"pack://application:,,,/TEST_MLT.ico"));
Upvotes: 1