title: Working with Resources in WPF
body: <p>I am wanting to use the example from </p>
  
  <p><a href="http://blogs.microsoft.co.il/blogs/tomershamam/archive/2008/09/22/lt-howto-gt-replace-listview-columns-with-rows-lt-howto-gt.aspx" rel="nofollow noreferrer">http://blogs.microsoft.co.il/blogs/tomershamam/archive/2008/09/22/lt-howto-gt-replace-listview-columns-with-rows-lt-howto-gt.aspx</a></p>
  
  <p>However I don't want to put this into the App.xaml code as this will apply to ALL gridviews, how do I apply this example to a select few gridviews in the application? The Resources look like this </p>
  
  <pre><code>&lt;Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}"
         TargetType="{x:Type ScrollViewer}"&gt;
          &lt;Setter Property="Focusable"
              Value="false"/&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type ScrollViewer}"&gt;
                      &lt;Grid Background="{TemplateBinding Background}"
                        SnapsToDevicePixels="true"&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition Width="*"/&gt;
                              &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="*"/&gt;
                              &lt;RowDefinition Height="Auto"/&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;DockPanel Margin="{TemplateBinding Padding}"&gt;
                              &lt;ScrollViewer DockPanel.Dock="Left"
                                        HorizontalScrollBarVisibility="Hidden"
                                        VerticalScrollBarVisibility="Hidden"
                                        Focusable="false"&gt;
                                  &lt;GridViewHeaderRowPresenter Margin="2,0,2,0"
                                                          Columns="{Binding Path=TemplatedParent.View.Columns,RelativeSource={RelativeSource TemplatedParent}}"
                                                          ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle,RelativeSource={RelativeSource TemplatedParent}}"
                                                          ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate,RelativeSource={RelativeSource TemplatedParent}}"
                                                          ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector,RelativeSource={RelativeSource TemplatedParent}}"
                                                          AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder,RelativeSource={RelativeSource TemplatedParent}}"
                                                          ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu,RelativeSource={RelativeSource TemplatedParent}}"
                                                          ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip,RelativeSource={RelativeSource TemplatedParent}}"
                                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt;
                              &lt;/ScrollViewer&gt;
                              &lt;ScrollContentPresenter Name="PART_ScrollContentPresenter"
                                      KeyboardNavigation.DirectionalNavigation="Local"
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      CanContentScroll="{TemplateBinding CanContentScroll}"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt;
                          &lt;/DockPanel&gt;
                          &lt;ScrollBar Name="PART_HorizontalScrollBar"
                                 Orientation="Horizontal"
                                 Grid.Row="1"
                                 Minimum="0.0"
                                 Maximum="{TemplateBinding ScrollableWidth}"
                                 ViewportSize="{TemplateBinding ViewportWidth}"
                                 Value="{Binding Path=HorizontalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                                 Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                                 Cursor="Arrow"/&gt;
                          &lt;ScrollBar Name="PART_VerticalScrollBar"
                                 Orientation="Vertical"
                                 Grid.Column="1"
                                 Minimum="0.0"
                                 Maximum="{TemplateBinding ScrollableHeight}"
                                 ViewportSize="{TemplateBinding ViewportHeight}"
                                 Value="{Binding Path=VerticalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                                 Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                 Cursor="Arrow"/&gt;
                          &lt;DockPanel Grid.Column="1"
                                 Grid.Row="1"
                                 Background="{Binding Path=Background,ElementName=PART_VerticalScrollBar}"
                                 LastChildFill="false"&gt;
                              &lt;Rectangle DockPanel.Dock="Left"
                                     Width="1"
                                     Fill="White"
                                     Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/&gt;
                              &lt;Rectangle DockPanel.Dock="Top"
                                     Height="1"
                                     Fill="White"
                                     Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/&gt;
                          &lt;/DockPanel&gt;
                      &lt;/Grid&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  
      &lt;Style TargetType="{x:Type GridViewHeaderRowPresenter}"&gt;
          &lt;Setter Property="Height" Value="80" /&gt;
          &lt;Setter Property="LayoutTransform"&gt;
              &lt;Setter.Value&gt;
                  &lt;TransformGroup&gt;
                      &lt;RotateTransform Angle="-90" /&gt;
                      &lt;ScaleTransform ScaleY="-1" /&gt;
                  &lt;/TransformGroup&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  
      &lt;Style TargetType="{x:Type GridViewRowPresenter}"&gt;
          &lt;Setter Property="LayoutTransform"&gt;
              &lt;Setter.Value&gt;
                  &lt;TransformGroup&gt;
                      &lt;RotateTransform Angle="-90" /&gt;
                      &lt;ScaleTransform ScaleY="-1" /&gt;
                  &lt;/TransformGroup&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  
      &lt;LinearGradientBrush x:Key="GridViewColumnHeaderBackground" EndPoint="0,1" StartPoint="0,0"&gt;
          &lt;GradientStop Color="#FFFFFFFF" Offset="0"/&gt;
          &lt;GradientStop Color="#FFFFFFFF" Offset="0.4091"/&gt;
          &lt;GradientStop Color="#FFF7F8F9" Offset="1"/&gt;
      &lt;/LinearGradientBrush&gt;
      &lt;LinearGradientBrush x:Key="GridViewColumnHeaderBorderBackground" EndPoint="0,1" StartPoint="0,0"&gt;
          &lt;GradientStop Color="#FFF2F2F2" Offset="0"/&gt;
          &lt;GradientStop Color="#FFD5D5D5" Offset="1"/&gt;
      &lt;/LinearGradientBrush&gt;
      &lt;LinearGradientBrush x:Key="GridViewColumnHeaderHoverBackground" EndPoint="0,1" StartPoint="0,0"&gt;
          &lt;GradientStop Color="#FFBDEDFF" Offset="0"/&gt;
          &lt;GradientStop Color="#FFB7E7FB" Offset="1"/&gt;
      &lt;/LinearGradientBrush&gt;
      &lt;LinearGradientBrush x:Key="GridViewColumnHeaderPressBackground" EndPoint="0,1" StartPoint="0,0"&gt;
          &lt;GradientStop Color="#FF8DD6F7" Offset="0"/&gt;
          &lt;GradientStop Color="#FF8AD1F5" Offset="1"/&gt;
      &lt;/LinearGradientBrush&gt;
      &lt;Style x:Key="GridViewColumnHeaderGripper" TargetType="{x:Type Thumb}"&gt;
          &lt;Setter Property="Canvas.Right" Value="-9"/&gt;
          &lt;Setter Property="Width" Value="18"/&gt;
          &lt;Setter Property="Height" Value="{Binding Path=ActualHeight, RelativeSource={RelativeSource TemplatedParent}}"/&gt;
          &lt;Setter Property="Padding" Value="0"/&gt;
          &lt;Setter Property="Background" Value="{StaticResource GridViewColumnHeaderBorderBackground}"/&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type Thumb}"&gt;
                      &lt;Border Background="Transparent" Padding="{TemplateBinding Padding}"&gt;
                          &lt;Rectangle Fill="{TemplateBinding Background}" HorizontalAlignment="Center" Width="1"/&gt;
                      &lt;/Border&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
      &lt;Style TargetType="{x:Type GridViewColumnHeader}"&gt;
          &lt;Setter Property="HorizontalContentAlignment" Value="Center"/&gt;
          &lt;Setter Property="VerticalContentAlignment" Value="Center"/&gt;
          &lt;Setter Property="Background" Value="{StaticResource GridViewColumnHeaderBackground}"/&gt;
          &lt;Setter Property="BorderBrush" Value="{StaticResource GridViewColumnHeaderBorderBackground}"/&gt;
          &lt;Setter Property="BorderThickness" Value="0"/&gt;
          &lt;Setter Property="Padding" Value="2,0,2,0"/&gt;
          &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type GridViewColumnHeader}"&gt;
                      &lt;Grid SnapsToDevicePixels="true"&gt;
                          &lt;Border x:Name="HeaderBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1"&gt;
                              &lt;Grid&gt;
                                  &lt;Grid.RowDefinitions&gt;
                                      &lt;RowDefinition MaxHeight="7"/&gt;
                                      &lt;RowDefinition/&gt;
                                  &lt;/Grid.RowDefinitions&gt;
                                  &lt;Rectangle Fill="#FFE3F7FF" x:Name="UpperHighlight" Visibility="Collapsed"/&gt;
                                  &lt;Border Grid.RowSpan="2" Padding="{TemplateBinding Padding}"&gt;
                                      &lt;ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0,0,0,1" x:Name="HeaderContent" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"&gt;
                                          &lt;ContentPresenter.LayoutTransform&gt;
                                              &lt;TransformGroup&gt;
                                                  &lt;ScaleTransform ScaleY="-1" /&gt;
                                                  &lt;RotateTransform Angle="90" /&gt;
                                              &lt;/TransformGroup&gt;
                                          &lt;/ContentPresenter.LayoutTransform&gt;
                                      &lt;/ContentPresenter&gt;
                                  &lt;/Border&gt;
                              &lt;/Grid&gt;
                          &lt;/Border&gt;
                          &lt;Border Margin="1,1,0,0" x:Name="HeaderHoverBorder" BorderThickness="1,0,1,1"/&gt;
                          &lt;Border Margin="1,0,0,1" x:Name="HeaderPressBorder" BorderThickness="1,1,1,0"/&gt;
                          &lt;Canvas&gt;
                              &lt;Thumb x:Name="PART_HeaderGripper" Style="{StaticResource GridViewColumnHeaderGripper}"/&gt;
                          &lt;/Canvas&gt;
                      &lt;/Grid&gt;
                      &lt;ControlTemplate.Triggers&gt;
                          &lt;Trigger Property="IsMouseOver" Value="true"&gt;
                              &lt;Setter Property="Background" TargetName="HeaderBorder" Value="{StaticResource GridViewColumnHeaderHoverBackground}"/&gt;
                              &lt;Setter Property="BorderBrush" TargetName="HeaderHoverBorder" Value="#FF88CBEB"/&gt;
                              &lt;Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/&gt;
                              &lt;Setter Property="Background" TargetName="PART_HeaderGripper" Value="Transparent"/&gt;
                          &lt;/Trigger&gt;
                          &lt;Trigger Property="IsPressed" Value="true"&gt;
                              &lt;Setter Property="Background" TargetName="HeaderBorder" Value="{StaticResource GridViewColumnHeaderPressBackground}"/&gt;
                              &lt;Setter Property="BorderBrush" TargetName="HeaderHoverBorder" Value="#FF95DAF9"/&gt;
                              &lt;Setter Property="BorderBrush" TargetName="HeaderPressBorder" Value="#FF7A9EB1"/&gt;
                              &lt;Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/&gt;
                              &lt;Setter Property="Fill" TargetName="UpperHighlight" Value="#FFBCE4F9"/&gt;
                              &lt;Setter Property="Visibility" TargetName="PART_HeaderGripper" Value="Hidden"/&gt;
                              &lt;Setter Property="Margin" TargetName="HeaderContent" Value="1,1,0,0"/&gt;
                          &lt;/Trigger&gt;
                          &lt;Trigger Property="Height" Value="Auto"&gt;
                              &lt;Setter Property="MinHeight" Value="20"/&gt;
                          &lt;/Trigger&gt;
                          &lt;Trigger Property="IsEnabled" Value="false"&gt;
                              &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/&gt;
                          &lt;/Trigger&gt;
                      &lt;/ControlTemplate.Triggers&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
          &lt;Style.Triggers&gt;
              &lt;Trigger Property="Role" Value="Floating"&gt;
                  &lt;Setter Property="Opacity" Value="0.4082"/&gt;
                  &lt;Setter Property="Template"&gt;
                      &lt;Setter.Value&gt;
                          &lt;ControlTemplate TargetType="{x:Type GridViewColumnHeader}"&gt;
                              &lt;Canvas x:Name="PART_FloatingHeaderCanvas"&gt;
                                  &lt;Rectangle Fill="#FF000000" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" Opacity="0.4697"/&gt;
                              &lt;/Canvas&gt;
                          &lt;/ControlTemplate&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/Trigger&gt;
              &lt;Trigger Property="Role" Value="Padding"&gt;
                  &lt;Setter Property="Template"&gt;
                      &lt;Setter.Value&gt;
                          &lt;ControlTemplate TargetType="{x:Type GridViewColumnHeader}"&gt;
                              &lt;Border x:Name="HeaderBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1"/&gt;
                              &lt;ControlTemplate.Triggers&gt;
                                  &lt;Trigger Property="Height" Value="Auto"&gt;
                                      &lt;Setter Property="MinHeight" Value="20"/&gt;
                                  &lt;/Trigger&gt;
                              &lt;/ControlTemplate.Triggers&gt;
                          &lt;/ControlTemplate&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/Trigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p>I have tried creating a usercontrol and sticking that lot in the UserControl.Resources section but it didn't work, I can only get this example to work if i put them into the Application.Resources section which i obviously don't want. Help!! :-)</p>