I am trying to create a style that applies only if the parent of the element to which the style belongs has a different special style. Like CSS, where you can do ".class1.class2" to indicate that the theme "class2" only applies if it is inside an element with class "class1".
I do not want to use any external libraries or libraries for this task. I want to know if I can implement it myself.
I tried using MultiTriggers with no luck.
I have a style that applies to all TextBlocks. I want the text block to do the following:
If the font size of the text block is 11 and the parent element's style is "PinnedSuggestion", set the foreground color to "# FF505050".
If the font size of the text block is 11 and the parent element's style is "Suggestion," set the foreground color to "#FFCCCCCC".
The conditions that I tried to write to do this work are as follows: the font size condition is true, and the other is not. Conditions are inside a style that applies to all text blocks in general.
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize}" Value="11" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Style}" Value="{StaticResource PinnedSuggestion}" />
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="#FFFF5050"></Setter>
</MultiDataTrigger>
I am not sure what I am doing wrong in this case. Below you see the ListBoxItem style for the Suggestion style. PinnedSuggestion looks exactly the same (with the exception of a few minor changes).
<Style x:Key="Suggestion" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Name="Container" Margin="0,0,0,0">
<Rectangle Margin="0,2,0,2" Stroke="Black" Name="Background" SnapsToDevicePixels="True" RadiusX="7" RadiusY="7" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
<Rectangle Margin="2,4,2,4" Name="BackgroundTwo" StrokeThickness="3" SnapsToDevicePixels="True" RadiusX="3" RadiusY="3" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
<ContentPresenter Margin="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Contentpresenter ListBoxItem - , , , .
, ...
ListBoxItem "" TextBlock. TextBlock (- ) , , , .
. , .