I have tried to give conditional styling using converter in style.setter as below,
<Style TargetType="DataGrid">
<Setter Property="Background" Value="{Binding Converter={StaticResource cc}}" />
</Style>
and came to know that there is no support provided for using converter in UWP. So please anyone suggest me better way to provide conditional styling in UWP using converter in style.setter
No, we don't have Trigger
support in UWP.
To keep the as much as light the triggers from UWP and Windows phone 8 are removed by msft. We could achieve those using Interactivity core. Blend(IDE) has great support to create trigger in these technologies.
Blend allows to define a behavior for the application Here.
We could define
DataTrigger
Use the DataTrigger trigger to invoke an action based on the value of a data-bound propertyEventTrigger
Use the EventTrigger trigger to invoke an action based on an event such as a mouse click, a page loading, or another interaction.KeyTrigger
Use the KeyTrigger trigger to invoke an action when a combination of keys is pressed on the keyboard.Note:- This are trigger available for windows phone,make sure UWP have this trigger in the blend SDK
A workaround is to use DataTriggerBehavior
with a ChangePropertyAction
to accomplish this.
xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" x:Class="XXX_XXXX"
This works for me
<DataGrid x:Name="MyGrid"
Stretch="None"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<interactivity:Interaction.Triggers>
<ec:DataTrigger Binding="{Binding IsBackgroundBlue}" Value="True">
<ec:ChangePropertyAction TargetObject="{Binding ElementName=MyGrid}" PropertyName="Background" Value="Blue" />
</ec:DataTrigger>
<!-- You could add your conditions here /> -->
</interactivity:Interaction.Triggers>
</DataGrid>
Pls mind this may not be correct syntax i dont have IDE now
Similar answer in https://stackoverflow.com/a/31933556/1876572
Msdn reference of triggers using visual state manager
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