In xaml it is :
<View:BaseWindow.Icon>
/VBDAdvertisement;component/Images/logoVBD.png
</View:BaseWindow.Icon>
I want to convert it into code behind.
Thanks
To add an icon to a project, right click on the project name in Solution Explorer. Right click will open Add Items menu. Select Add >> New Item. Now on Installed Templates, select Icon File (see Figure 1) and click Add.
Something like
myWindow.Icon = new BitmapImage(new Uri("/VBDAdvertisement;component/Images/logoVBD.png"));
You may need to qualify the path more though.
Edit: As i thought the path should be in pack-uri format:
"pack://application:,,,/VBDAdvertisement;component/Images/logoVBD.png"
This is the correct way to do it (assuming MyIcon.ico is placed on the root folder of a WPF project named MyApplication):
Uri iconUri = new Uri("pack://application:,,,/MyApplication;component/MyIcon.ico");
myWindow.Icon = BitmapFrame.Create(iconUri);
This is also what actually happens when you set the Icon property for the window in XAML.
When just setting the Icon to a new Bitmap, it will not be rendered smoothly and correctly, but instead quite a bit pixelated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With