I have a WPF project with a window. If I want to set the window's icon property in C#, it allow me to feed it only an ImageSource and it doesn't accept icon files. If I set the property in XAML, it accepts icon files without any problem. How can I set the a WPF Window's icon to an icon file through C# code?
Asked
Active
Viewed 9,808 times
2
-
Does this answer your question? [How to set window icon in code behind in wpf?](https://stackoverflow.com/questions/8254281/how-to-set-window-icon-in-code-behind-in-wpf) – StayOnTarget Mar 19 '20 at 14:27
1 Answers
5
How about
mywindow.Icon = new BitmapImage(new Uri(@"C:\myicon.ico"));

Nikhil Agrawal
- 47,018
- 22
- 121
- 208
-
Cool, thank you! I will be allowed to accept the answer in 9 minutes. Could you also give me a hint about how to set the window's icon to an icon file from the resource file? – IneedHelp Sep 12 '12 at 16:46
-
1@IneedHelp: Read this http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code – Nikhil Agrawal Sep 12 '12 at 16:48