Search code examples
wpficonscode-behind

How to set window icon in code behind in wpf?


In xaml it is :

  <View:BaseWindow.Icon>
    /VBDAdvertisement;component/Images/logoVBD.png
  </View:BaseWindow.Icon>

I want to convert it into code behind.

Thanks


Solution

  • 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"