Q:

wpf use elements declared in style

i'm in trouble joining styles and code in my form:
here is my situation:
my TabItem style:
   <Style TargetType="TabItem" x:Key="testStyle">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Padding" Value="6,2,6,2" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="MinWidth" Value="5" />
        <Setter Property="MinHeight" Value="5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TabItem">
                    <DockPanel Width="120" x:Name="rootPanel">
                        <ContentPresenter ContentSource="Header"  RecognizesAccessKey="True" />
                        <Image x:Name="rootImage"/>
                        <Label x:Name="rootLabel" FontSize="18" />
                    </DockPanel>
                    <ControlTemplate.Triggers>

and here is where I apply my style
            <TabItem Style="{StaticResource testStyle}">
                <TabItem.Header>

                </TabItem.Header>

but: how can I set the values to my Image and label called rootImage and rootLabel?

A:

I assume you have a class named SomeClass
public class SomeClass
{
    public string SomeLabel;
    public string SomeImage;
}

Now change your style
<DockPanel Width="120" x:Name="rootPanel">
    <ContentPresenter ContentSource="Header"  RecognizesAccessKey="True" />
    <Image x:Name="rootImage" Source={Binding SomeImage}/>
    <Label x:Name="rootLabel" Content={Binding SomeLabel} FontSize="18" />
</DockPanel>

Finally: 
<TabItem Style="{StaticResource testStyle}" Name="myTabItem">
    <TabItem.Header>

    </TabItem.Header>
</TabItem>

And in the code behind:
myTabItem.DataContext = new SomeClass(); //create a SomeClass with proper label and image

