MultiTrigger with or condition

AmiteshSharma.5497AmiteshSharma.5497 NZMember ✭✭
edited January 2018 in Xamarin.Forms

Hi
I have added a trigger on my stacklayout to make it visible when one or more conditions are met. I dont want to create a property in my model to bind to the stacklayout. My issue is that the trigger treats the conditions with AND operator.
Is there a way to make it treat the conditions with OR operator? So in my case if IsPrivate is true or IsAlert is true the stacklayout should be visible.

Sample code below:

Answers

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited September 2018

    Set the value of "IsVisible" is "False" by default, then use separate DataTriggers instead of a MultiTrigger

    <StackLayout IsVisible="False">
        <StackLayout.Triggers>
            <DataTrigger TargetType="StackLayout" Binding="{Binding IsPrivate}" Value="True">
                <Setter Property="IsVisible" Value="True" />
            </DataTrigger>
            <DataTrigger TargetType="StackLayout" Binding="{Binding IsAlert}" Value="True">
                <Setter Property="IsVisible" Value="True" />
            </DataTrigger>
        </StackLayout.Triggers>
    <StackLayout>
    

    Doing this will always have the StackLayout visibility set to False unless IsPrivate is true OR IsAlert is true

    Happy coding!

Sign In or Register to comment.