Is there a way to add binding in Value section of data Trigger

stXamDevstXamDev Member ✭✭
edited April 24 in Xamarin.Forms


  • TaylorDTaylorD USMember ✭✭✭

    Here is the code from the post formatted properly.

    <DataTrigger TargetType="StackLayout" Binding="{Binding IsRAFlagVisible}" Value="{Binding MyVariable}">
        <Setter Property="BackgroundColor" Value="DarkGray"/>
  • LandLuLandLu Member, Xamarin Team Xamurai

    Is this what you are looking for
    It specifies how to use binding in data trigger.

  • stXamDevstXamDev Member ✭✭

    @TaylorD Thanks
    @LandLu In the code I need to bind the Value field from the code and not as a static value

  • LandLuLandLu Member, Xamarin Team Xamurai

    We can't use binding for the DataTrigger's Value. But we could use a static property to change the value:

    <Entry x:Name="entry" Text="" Placeholder="required field" />
    <Button x:Name="button" Text="Save" FontSize="Large" HorizontalOptions="Center">
            <DataTrigger TargetType="Button" 
                        Binding="{Binding Source={x:Reference entry}, Path=Text.Length}" 
                        Value="{x:Static local:PublicConstants.TextLength}">
                <Setter Property="IsEnabled" Value="{Binding IsEnabled}" />

    Define a static property:

    public class PublicConstants
        public static int TextLength { get => 2; }

    Moreover, we could use binding for Setter's Value.

Sign In or Register to comment.