Note that there are some explanatory texts on larger screens.

plurals
  1. POA style that activates depending on another style?
    text
    copied!<p>I am trying to make a style that only gets applied if the parent element of the element that the style refers to, has another specific style. Kind of like in CSS where you can do ".class1 .class2" to specify that the "class2" theme only applies if it is within an element with the class "class1".</p> <p>I do not wish to use any form of external DLLs or libraries for this task. I want to know if it's possible to implement on my own.</p> <p>I've tried using MultiTriggers with no luck.</p> <p>I have a style that applies to all TextBlocks. I want the textblock to do the following:</p> <p><em><strong>If the font-size of the textblock is 11 and the parent element's style is "PinnedSuggestion", set the foreground color to "#FF505050".</em></strong></p> <p><em><strong>If the font-size of the textblock is 11 and the parent element's style is "Suggestion", set the foreground color to "#FFCCCCCC".</em></strong></p> <p>The conditions that I have tried to write to make this work, are as follows (the font-size condition is true, but the other one is not). The conditions are inside a style that applies to all textblocks in general.</p> <pre><code> &lt;MultiDataTrigger&gt; &lt;MultiDataTrigger.Conditions&gt; &lt;Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize}" Value="11" /&gt; &lt;Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Style}" Value="{StaticResource PinnedSuggestion}" /&gt; &lt;/MultiDataTrigger.Conditions&gt; &lt;Setter Property="Foreground" Value="#FFFF5050"&gt;&lt;/Setter&gt; &lt;/MultiDataTrigger&gt; </code></pre> <p>I am not sure what I am doing wrong in this case. Below you see my ListBoxItem style for the "Suggestion" style. The PinnedSuggestion looks exactly the same (except for a few minor changes).</p> <pre><code>&lt;Style x:Key="Suggestion" TargetType="{x:Type ListBoxItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ListBoxItem"&gt; &lt;Grid Name="Container" Margin="0,0,0,0"&gt; &lt;Rectangle Margin="0,2,0,2" Stroke="Black" Name="Background" SnapsToDevicePixels="True" RadiusX="7" RadiusY="7" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;&lt;/Rectangle&gt; &lt;Rectangle Margin="2,4,2,4" Name="BackgroundTwo" StrokeThickness="3" SnapsToDevicePixels="True" RadiusX="3" RadiusY="3" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;&lt;/Rectangle&gt; &lt;ContentPresenter Margin="0"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>The contentpresenter of that ListBoxItem style is what contains the textblocks that I want this technique to work with.</p> <p>So, to summarize...</p> <p>A ListBoxItem with the style "Suggestion" applied will have a TextBlock in it. The TextBlock style (due to its target type) will automatically apply to that, and I want the multitrigger conditions described above to work as they should.</p> <p>My situation is kind of hard to explain. I explained everything as well as I could.</p>
 

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