I want to change the style based on binding values, for this I used DataTriggers in WPF. Now I'm trying to achieve the same in WinUI project, but since there are no DataTriggers in WinUI I can't go further.
In further analysis, I found the package Microsoft.Xaml.Behaviors.WinUI.Managed to use behaviors in WinUI project but I can't install this in WinUI UWP project.
Note: Since VisualStateManager only includes common states I can't apply that here.
I found the package Microsoft.Xaml.Behaviors.WinUI.Managed to use behaviors in WinUI project but I can't install this in WinUI UWP project.
The available xaml behaviors package is Microsoft.Xaml.Behaviors.Uwp.Managed, you could install it into your uwp project, and use DataTriggerBehavior to control you xaml base on the specific bindind data.
<Rectangle x:Name="DataTriggerRectangle">
<Interactivity:Interaction.Behaviors>
<Interactions:DataTriggerBehavior Binding="{Binding Value, ElementName=slider}" ComparisonCondition="GreaterThan" Value="50">
<Interactions:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="{StaticResource PaleYellowBrush}"/>
</Interactions:DataTriggerBehavior>
<Interactions:DataTriggerBehavior Binding="{Binding Value, ElementName=slider}" ComparisonCondition="LessThanOrEqual" Value="50">
<Interactions:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="{StaticResource RoyalBlueBrush}"/>
</Interactions:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Rectangle>
Here is official document that you could refer, and here is official code sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With