AnsweredAssumed Answered

How to set XAML window icon

Question asked by Peter Brinkhuis on May 28, 2020
Latest reply on May 30, 2020 by Peter Brinkhuis

I have a SOLIDWORKS add-in, which creates a new window. I would like to set the icon for this window. How do I do that, either in XAML or in code-behind?

 

My image is a .ICO file or PNG. All examples I could find use ICO files. I've set the images as an embedded resource and it copies to the output folder. Yet I keep getting IO exceptions, without those telling me the exact path they are trying to find.

 

I've tried it in XAML:

Icon="/CADBooster.Tool.Addin;component/icon.ico">

or 
<Window.Icon>
<BitmapImage UriSource="/CADBooster.Tool.Addin;component/icon.ico" />
</Window.Icon>

 

I've tried the code-behind:

var iconUri = new Uri("/CADBooster.Tool.Addin;component/icon.ico", UriKind.RelativeOrAbsolute);
Icon = BitmapFrame.Create(iconUri);

 

I've also tried the format pack://application,,,/CADBooster.Tool.Addin;component 

 

Any ideas?

Outcomes