title: WPF - Create reusable style with variables/parameters
body: <p>I have an WPF application which contains several TabItems. Each TabItem is different from each other, with a text and an icon.</p>
  
  <p>This is how the TabItem´s style is defined:</p>
  
  <pre><code>&lt;TabItem.Style&gt;
                      &lt;Style TargetType="TabItem"&gt;
                          &lt;Setter Property="Header"&gt;
                              &lt;Setter.Value&gt;
                                  &lt;StackPanel Orientation="Horizontal"&gt;
                                      &lt;Image Margin="10,0,0,0" Height="40" Width="40" Source="Images/IconLeafGrey.png"/&gt;
                                      &lt;TextBlock Text="This is the heading" VerticalAlignment="Center" Style="{StaticResource Heading2}" Margin="10,0,0,0"/&gt;
                                  &lt;/StackPanel&gt;
                              &lt;/Setter.Value&gt;
                          &lt;/Setter&gt;
                          &lt;Setter Property="Template"&gt;
                              &lt;Setter.Value&gt;
                                  &lt;ControlTemplate TargetType="{x:Type TabItem}"&gt;
                                      &lt;Grid&gt;
                                          &lt;Border Name="Border" BorderBrush="Black" BorderThickness="1,1,1,1" CornerRadius="6,6,0,0" &gt;
                                              &lt;Border.Background&gt;
                                                  &lt;LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"&gt;
                                                      &lt;GradientStop Color="#f5f7f8" Offset="0.0" /&gt;
                                                      &lt;GradientStop Color="#c5d0dd" Offset="1.0" /&gt;
                                                  &lt;/LinearGradientBrush&gt;
                                              &lt;/Border.Background&gt;
                                              &lt;ContentPresenter Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Left" ContentSource="Header" Margin="5,2,0,2"/&gt;
                                          &lt;/Border&gt;
                                      &lt;/Grid&gt;
                                      &lt;ControlTemplate.Triggers&gt;
                                          &lt;Trigger Property="IsSelected" Value="True"&gt;
                                              &lt;Setter Property="Background" TargetName="Border"&gt;
                                                  &lt;Setter.Value&gt;
                                                      &lt;LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"&gt;
                                                          &lt;LinearGradientBrush.GradientStops&gt;
                                                              &lt;GradientStop Color="#ebedee" Offset="0.0" /&gt;
                                                              &lt;GradientStop Color="#88a2bd" Offset="1.0" /&gt;
                                                          &lt;/LinearGradientBrush.GradientStops&gt;
                                                      &lt;/LinearGradientBrush&gt;
                                                  &lt;/Setter.Value&gt;
                                              &lt;/Setter&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="IsSelected" Value="True"&gt;
                                  &lt;Setter Property="Header"&gt;
                                      &lt;Setter.Value&gt;
                                          &lt;StackPanel Orientation="Horizontal"&gt;
                                              &lt;Image Margin="10,0,0,0" Height="40" Width="40" Source="Images/IconLeaf.png"/&gt;
                                              &lt;TextBlock Text="This is the heading" VerticalAlignment="Center" Style="{StaticResource Heading2}" Margin="10,0,0,0"/&gt;
                                          &lt;/StackPanel&gt;
                                      &lt;/Setter.Value&gt;
                                  &lt;/Setter&gt;
  
                              &lt;/Trigger&gt;
                          &lt;/Style.Triggers&gt;
                      &lt;/Style&gt;
                  &lt;/TabItem.Style&gt;
  </code></pre>
  
  <p>So instead of writing this XAML markup for each TabItem, I would like to define this style once in my ResourceDictionary, but with the Icon and the Text property as optional parameters. So I afterwards could define a TabItem like this:</p>
  
  <pre><code>&lt;TabItem Width="250" Height="60" Style="{StaticResource CustomTabItem}" &gt;
  </code></pre>
  
  <p>I´ve read that it isnt directly possible for a style to accept parameters like this, but it should be posible with some sort of binding. I havent found out exactly how though, so I really hope you can help.</p>
  
  <p>Kind regards.</p>