I have a MAUI ContentPage with the ViewModel. In this page, I have a Picker that saves the selected item in the property WordType (it can be Noun or Verb).
<Picker x:Name="pickerWordType"
ItemsSource="{Binding WordTypes}"
SelectedItem="{Binding WordType}"
Style="{StaticResource pickerEditStyle}">
</Picker>
When the selected value is Verb, I want to display a Label and an Entry. For this reason, I use the Triggers. I wrote the following XAML:
<Label Text="Infinite" IsVisible="false">
<Label.Triggers>
<MultiTrigger TargetType="Label">
<MultiTrigger.Conditions>
<BindingCondition Binding="{Binding WordType}" Value="Verb" />
</MultiTrigger.Conditions>
<Setter Property="IsVisible" Value="true" />
</MultiTrigger>
</Label.Triggers>
</Label>
<Entry BindingContext="{Binding Tense1}" IsVisible="false">
<Entry.Triggers>
<MultiTrigger TargetType="Entry">
<MultiTrigger.Conditions>
<BindingCondition Binding="{Binding WordType}" Value="Verb" />
</MultiTrigger.Conditions>
<Setter Property="IsVisible" Value="true" />
</MultiTrigger>
</Entry.Triggers>
</Entry>
The Triggers is working for the Label but not for the Entry and the conditions are exactly the same.
>Solution :
The problem is that WordType probably doesn’t exist in the BindingContext that you’re passing to the Entry. If exactly the same code works for the Label, then remove the BindingContext from the Entry:
<Entry IsVisible="false">
<Entry.Triggers>
<MultiTrigger TargetType="Entry">
<MultiTrigger.Conditions>
<BindingCondition Binding="{Binding WordType}" Value="Verb" />
</MultiTrigger.Conditions>
<Setter Property="IsVisible" Value="true" />
</MultiTrigger>
</Entry.Triggers>
</Entry>