Search code examples
c#wpfbindingiconsapplication-icon

Why is my application icon not transparent?


In XAML, I am attempting to bind the window/application icon to an icon on the file system.

In Window.xaml

Icon="{Binding ApplicationIcon}"

In AppViewModel.cs

public ImageSource ApplicationIcon
{
  get
  {
    return new BitmapImage(new Uri(pathReadFromConfigFile));
  }
}

When I do this, the icon is shown but it is not transparent. However, if I set the icon within the project (not using binding), the icon is added to the project and it is transparent when I start the application. Why is it acting differently between these two scenarios?


Solution

  • Figured it out. It was the BitMapImage creation causing the problems. Using BitmapFrame now instead.

    public ImageSource ApplicationIcon
    {
      get
      {
        return BitmapFrame.Create(new Uri(pathReadFromConfigFile));
      }
    }