Search code examples
wpfxamltabcontrol

Error: Cannot find the Template Property 'Foreground' on the type 'System.Windows.Controls.Grid'


I'm trying to add the Property 'Foreground' in the ControlTemplate Trigger of Tab Control :

                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter TargetName="Panel" Property="Background" Value="LightSkyBlue" />
                                    </Trigger>
                                    <Trigger Property="IsSelected" Value="False">
                                        <Setter TargetName="Panel" Property="Background" Value="Gray" />
                                        <Setter  Property="Foreground" TargetName="Panel" Value="White"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>

Unfortunately , I get this error :

Error Cannot find the Template Property 'Foreground' on the type 'System.Windows.Controls.Grid'.

How can I fix this error?


Solution

  • I fixed the error by adding :

     <Setter Property="TextElement.Foreground" TargetName="Panel" Value="White"></Setter>
    

    So the complete code will be :

                      <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter TargetName="Panel" Property="Background" Value="LightSkyBlue" />
                                </Trigger>
                                <Trigger Property="IsSelected" Value="False">
                                    <Setter TargetName="Panel" Property="Background" Value="Gray" />
     <Setter Property="TextElement.Foreground" TargetName="Panel" Value="White"/>
    
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>