Style Trigger for PackIcon #2720
-
Hi guys! I am writing a to-do list app for my school project and I'm stuck. Maybe someone could help me. Here is the code
I can't realize why the style trigger for text block works just fine, but for IconPack it not working. These controls are placed just like here, one after another. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@enumerable-entity I assume the issue you are running into is the To get the behavior you want, you need to set the default value in the style and then the trigger can override it. Something like this: <materialDesign:PackIcon
Kind="Calendar"
DockPanel.Dock="Right"
VerticalAlignment="Center"
Height="15"
Width="15"
Margin="10,0,5,0">
<materialDesign:PackIcon.Style>
<Style TargetType="materialDesign:PackIcon" BasedOn="{StaticResource {x:Type materialDesign:PackIcon}}">
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsCompleted}" Value="true">
<Setter Property="Foreground" Value="Gray"/>
</DataTrigger>
</Style.Triggers>
</Style>
</materialDesign:PackIcon.Style>
</materialDesign:PackIcon> A few other minor details I changed:
|
Beta Was this translation helpful? Give feedback.
@enumerable-entity I assume the issue you are running into is the
Foreground
property not changing on yourPackIcon
whenIsCompleted
is set to true. The reason for this is because you have set theForeground
property on the PackIcon directly. Within WPF, these direct assignments always take precedence over anything in a style; which is why the style trigger does not appear to work.To get the behavior you want, you need to set the default value in the style and then the trigger can override it. Something like this: