title: How to set the background image of all windows in wpf application
body: <p>I want to set the background image of all windows and style of all data grids in all windows of my wpf application in a single place</p>
  
  <p>I have the following code in my app.xaml file</p>
  
  <pre><code>&lt;Application.Resources&gt;
  
      &lt;!--Styles for woindow--&gt;
      &lt;ImageBrush x:Key="WindowBackgroungImage" ImageSource="Icons\clinic.jpg"/&gt;
      &lt;LinearGradientBrush x:Key="WindowBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0" &gt;
          &lt;GradientStop Color="Black" Offset="0"/&gt;
          &lt;GradientStop Color="White" Offset="1"/&gt;
      &lt;/LinearGradientBrush&gt;
  
      &lt;!--Styles for Data Grid--&gt;
      &lt;Style x:Key="DGCHeaderStyle" TargetType="DataGridColumnHeader"&gt;
          &lt;Setter Property="Foreground" Value="Black"/&gt;
          &lt;Setter Property="FontSize" Value="14" /&gt;
          &lt;Setter Property="FontFamily" Value="Calibri" /&gt;
          &lt;Setter Property="FontWeight"  Value="SemiBold" /&gt;
          &lt;!--&lt;Setter Property="HorizontalAlignment" Value="Center" /&gt;--&gt;
          &lt;Setter Property="HorizontalContentAlignment" Value="Center" /&gt;
      &lt;/Style&gt;
  
      &lt;LinearGradientBrush x:Key="DataGridRowBackground" EndPoint="195.5,455" StartPoint="195.5,0" MappingMode="Absolute" SpreadMethod="Repeat"&gt;
          &lt;GradientStop Color="Black" Offset="0"/&gt;
          &lt;GradientStop Color="#FF0FC9E6" Offset="1"/&gt;
          &lt;GradientStop Color="#FF6CA3AC"/&gt;
      &lt;/LinearGradientBrush&gt;
      &lt;RadialGradientBrush x:Key="DataGridAlternatingRowBackground" SpreadMethod="Reflect" Center="195.5,227.5" GradientOrigin="195.5,227.5" MappingMode="Absolute" RadiusY="227.5" RadiusX="195.5"&gt;
          &lt;GradientStop Color="Black" Offset="0"/&gt;
          &lt;GradientStop Color="#FFEEA21F" Offset="1"/&gt;
          &lt;GradientStop Color="#FFF7F3E9"/&gt;
      &lt;/RadialGradientBrush&gt;
  
      &lt;Style TargetType="DataGrid"&gt;
          &lt;Setter Property="ColumnHeaderStyle" Value="{DynamicResource DGCHeaderStyle}"/&gt;
          &lt;Setter Property="Background" Value="{x:Null}" /&gt;
          &lt;Setter Property="HorizontalGridLinesBrush" Value="Black"/&gt;
          &lt;Setter Property="VerticalGridLinesBrush" Value="Black"/&gt;
          &lt;Setter Property="RowBackground" Value="{StaticResource DataGridRowBackground}"/&gt;
          &lt;Setter Property="AlternatingRowBackground" Value="{StaticResource DataGridAlternatingRowBackground}" /&gt;
      &lt;/Style&gt;
  
      &lt;!--Settin window style--&gt;
      &lt;Style TargetType="Window"&gt;
          &lt;Setter Property="BorderBrush" Value="{StaticResource WindowBorderBrush}"/&gt;
          &lt;Setter Property="Background" Value="{StaticResource WindowBackgroungImage}"/&gt;
      &lt;/Style&gt;
  
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>The style of DataGrid is applied as desired in designer and also when i start debugging
  The background image appears in designer in visual studio as desired but it is not shown in any window when i start the application in debugging mode.</p>
  
  <p>when I add the following lines in 'mainwindow.xaml' file the background image appears as desired</p>
  
  <pre><code>&lt;Window.Background&gt;
      &lt;ImageBrush  ImageSource="Icons\clinic.jpg"/&gt;
  &lt;/Window.Background&gt;
  </code></pre>
  
  <p>I have an icons folder in my project in which the background image is placed with the name of clinic.jpg</p>