Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multitriggers doesn't work with Entry in MAUI

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading