Reputation: 6202
I'm trying to define some triggers in the XAML without success. What I want to do is quite simple. I have a 3 Grids for 3 steps in my app, like a wizard.
In the ViewModel I have a property where I save the current step. If the step the Grid has the same value of this property, I want to display the Grid. I thought I could you Triggers
like in Xamarin but apparently it doesn't work.
<Grid x:Name="firstStep" Margin="30" ColumnSpacing="15">
<Grid.Style>
<Setter Property="Visibility" Value="Collapse" />
<Style.Triggers>
<DataTrigger Binding="{Binding Value}" Value="1">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Grid.Style>
</Grid>
How can I implement something like that? What is the best practice?
Upvotes: 0
Views: 222
Reputation: 252
In UWP, triggers are deprecated and there is only one kind of officially supported trigger – AdaptiveTrigger for responsive design. In general, recommended replacement for them are Behaviors and Actions (see https://www.nuget.org/packages/Microsoft.Xaml.Behaviors.Uwp.Managed/). In addition, there are some unofficial Triggers in the Community Toolkit.
But in your case it would be better to just make a custom converter. Create a class implementing IValueConverter, take an integer number of the step from parameter and return Visibility.Visible when value and parameter match. Add object of that class to resources and specify converter with parameter = stepnumber in the binding.
Upvotes: 1