Note that there are some explanatory texts on larger screens.

plurals
  1. POOverriding implicit styles in nested controls
    primarykey
    data
    text
    <p>i have a resource dictionary in my app , in which their is a generic style defined for textblock , this dictionary is merged with app.xaml.</p> <p>Now i have a requirement where i need to change the style of tabitem in my dialog window and set foreground based on few triggers,i have defined my own textblock style and written template for tabitem and textblock as below-</p> <pre><code>/* wriiten in common style */ &lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="Foreground" Value="{StaticResource BR_SE_Black}" /&gt; &lt;Setter Property="TextTrimming" Value="CharacterEllipsis"/&gt; &lt;Setter Property="FontSize" Value="11"/&gt; &lt;Setter Property="FontFamily" Value="Arial Unicode MS"/&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="controls:TextBlockService.IsTextTrimmed" Value="True"&gt; &lt;Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; /* written in dialog winow */ &lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="VerticalAlignment" Value="Center"&gt;&lt;/Setter&gt; &lt;Setter Property="TextTrimming" Value="CharacterEllipsis"/&gt; &lt;Setter Property="FontSize" Value="11"/&gt; &lt;Setter Property="FontFamily" Value="Arial Unicode MS"/&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Controls:TextBlockService.IsTextTrimmed" Value="True"&gt; &lt;Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type TabControl}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TabControl}" &gt; &lt;Grid KeyboardNavigation.TabNavigation="Local"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;RowDefinition Height="*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;TabPanel Name="HeaderPanel" Grid.Row="0" Panel.ZIndex="1" Margin="0,0,0,-1" IsItemsHost="True" KeyboardNavigation.TabIndex="1" Background="Green" /&gt; &lt;Border Name="Border" Grid.Row="1" Background="#FFFFFF" BorderBrush="#888888" BorderThickness="1" KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" &gt; &lt;ContentPresenter Name="PART_SelectedContentHost" Margin="4" ContentSource="SelectedContent" /&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;!-- SimpleStyles: TabItem --&gt; &lt;Style TargetType="{x:Type TabItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TabItem}"&gt; &lt;Grid&gt; &lt;Border Name="Border" Margin="0,0,-4,0" Background="Green" CornerRadius="3" BorderBrush="Transparent" BorderThickness="1,1,1,1" &gt; &lt;ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="12,2,12,2" RecognizesAccessKey="True" /&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="Panel.ZIndex" Value="100" /&gt; &lt;Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" /&gt; &lt;Setter TargetName="Border" Property="Background" Value="White" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Foreground" Value="white"&gt;&lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="Foreground" Value="Green"&gt;&lt;/Setter&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>The issue which i am facing now is foreground colour which i am trying to set in tabitem template for tabitem header is not getting applied , and it is taking the colour defined in base textblock style , if i comment the foreground colour setting in base textblock style everything works fine, any idea why this issue is happening , and how can it be fixed?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload