views:

314

answers:

0

How do I change an image source within my TabControl > TabItem > TabItem.Header using triggers? Here's what I have so far:

        <TabControl Name="tabctlMainTab" 
                    Style="{StaticResource PrimaryTabControl}"
                    SelectionChanged="MainTab_SelectionChanged" Background="Transparent">
            <TabItem IsSelected="True">
                <TabItem.Header>
                    <Image Name="imgProjectCreate" 
                           Style="{StaticResource PrimaryTabItemImage}"
                           Source="/PROJECT.Desktop;component/Images/PrimaryTabs/tab_left_create_project_on.png" />
                </TabItem.Header>
                <TabItem.Style>
                    <Style BasedOn="{StaticResource PrimaryTabItem}" TargetType="{x:Type TabItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type TabItem}">
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="imgProjectCreate" Property="Source" Value="/PROJECT.Desktop;component/Images/PrimaryTabs/tab_left_create_project_on.png" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </TabItem.Style>
            </TabItem>
            <TabItem Style="{StaticResource PrimaryTabItem}">
                <TabItem.Header>
                    <Image Style="{StaticResource PrimaryTabItemImage}"
                           Source="/PROJECT.Desktop;component/Images/PrimaryTabs/tab_left_modify_project_off.png" />
                </TabItem.Header>

            </TabItem>
        </TabControl>


But, I get this error:

Cannot find the Trigger target 'imgProjectCreate'. (The target must appear before any Setters, Triggers, or Conditions that use it.)

I'm completely new to WPF and XAML so any help would be greatly appreciated.

Thanks!