Question

I'm going to set Window.Icon property by using ResourceDictionary like below:

<Style TargetType="{x:Type Window}">
    <Setter Property="Icon" Value="/WpfApplication1;component/Resources/Icon.ico" />
</Style>

Above Style wasn't change Icon of Window. However when i set Icon of Window directly, It is done correctly!

<Window Icon="/WpfApplication1;component/Resources/Icon.ico">
    //Content
</Window>

Note: Build Action of Icon.ico was set to Resource and ResourceDictionary also loaded.

Was it helpful?

Solution

The problem is that your style is not applied at all. You'll have to define your style in app.xaml, assign a key to it and set your windows style explicitly.
EDIT:
Goblin suggested another valuable solution, excerpt from his comment:
he could set the TargetType="{local:MainWindow}" where local is the namespace for WPFApplication1. The problem is that 'empty key'-application works only for the specified type - not descendants.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top