title: Set window icon in style
body: <p>I would like to use the same icon for my main window and for any dialogs or message boxes whithin my application, so I tried to set it like this in a ResourceDictionary:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type Window}"&gt;
    &lt;Setter Property="Icon" Value="pack://application:,,,/MyReferenceAssemblyName;component/Images/myIcon.gif"&gt;&lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>But that does not work. 
  How could I share the same icon with the different windows?</p>
  
  <p>Edit:</p>
  
  <p>I have a simple resource dictionary (Style.xaml) where I am defining some global settings. I use it in my App.xaml like this:</p>
  
  <pre><code>&lt;Application.Resources&gt;
    &lt;ResourceDictionary&gt;
      &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source="Resources/ViewModelTemplates.xaml"/&gt;
        &lt;ResourceDictionary Source="Resources/Style.xaml"/&gt;
      &lt;/ResourceDictionary.MergedDictionaries&gt;
    &lt;/ResourceDictionary&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>The file contains some definitions like e.g. button height, text box foreground color, etc.
  There is no problem with those and all the panels and window my application creates use these settings. That is why I would like the icon to be defined there as well, to have it used allover the application.</p>
  
  <p>I am not looking for a way to set the icon of the .exe file.</p>
  
  <p>Edit:</p>
  
  <p>I have not found the solution for what I want to do, so I ended up creating a BitmapImage in my ResourceDictionary and use it as DynamicResource in each of my Window-Classes.</p>
  
  <pre><code>&lt;BitmapImage x:Key="ApplicationIcon" UriSource="pack://application:,,,/MyReferenceAssemblyName;component/Images/myIcon.gif"&gt;&lt;/BitmapImage&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;Window ...        
      Closing="Window_Closing"
      Title="{Binding Title, UpdateSourceTrigger=PropertyChanged}"
      IsEnabled="{Binding IsEnabled, FallbackValue=True, Mode=OneWay}" 
      WindowState="Maximized"
      Icon="{DynamicResource ApplicationIcon}"&gt;
      ...
  &lt;/Window&gt;
  </code></pre>