Crystal
Crystal

Reputation: 29458

Windows Icon property in WPF, Markup Extension needed?

I have an icon that I added to my application. It shows up in the first window that gets presented. When I present a new window, and I use the

Icon="ApplicationIcon.ico"

in my Window, it crashes. When I remove that line, my code runs fine. I'm trying to get rid of the default icon Windows provides and use the one that my application is using. I double checked the path, but it does not work. I get the error:

Xaml parse exception occurred: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '7' and line position '9'.

Inner Exception: {"Cannot locate resource 'views/applicationicon.ico'."}
System.IO.IOException: {"Cannot locate resource 'views/applicationicon.ico'."}

Upvotes: 2

Views: 3673

Answers (5)

Curtis
Curtis

Reputation: 5892

I had this same issue. I ended up setting the Build Action for the icon to 'Content' and set the Copy to Output Directory option to 'Copy always', and it worked like a charm.

Upvotes: 0

praveen m
praveen m

Reputation: 11

Use single file for all you WPF windows in your solution By setting following........

Icon="pack://application:,,,/ReferenceAssemblyname;component/Subfoldername/filename.ico"

Upvotes: 1

brunnerh
brunnerh

Reputation: 184506

The path is relative and for windows located in other places it will not work, you could make it absolute using pack notation:

Icon="pack://application:,,,/ApplicationIcon.ico"

Upvotes: 0

Louis Kottmann
Louis Kottmann

Reputation: 16628

I'm gonna take a wild guess here and say that your other windows are not in the same folder than your main window. If that's the case, add "..", something like "..\ApplicationIcon.ico".

Upvotes: 0

Jakub
Jakub

Reputation: 534

It seems like you're using the the application icon incorrectly. Since this is a WPF application you should have a WPF project in your workspace. Select that project's properties and go to "Application". Under resources you can select the relative location of your icon which will then replace the default WPF app icon. Note that the icon doesn't usually appear when the application is run in debug mode. To make it appear the app should be run without debugging or in release mode.

Upvotes: 1

Related Questions