How should i enable and disable a button Based on all valid inputs?

RamprasadKRamprasadK USMember ✭✭

How should i enable and disable a button Based on all valid inputs?
And here the validation works good, but not button!!

Thanks in advance!

Best Answer

  • RamprasadKRamprasadK US ✭✭
    Accepted Answer

    Here is my updated Code and its working.

    <Button Text="Create Data" IsEnabled="False" x:Name="CreateButton"> <!--<Style TargetType="Button"> <Style.Triggers>--> <Button.Triggers> <MultiTrigger TargetType="Button"> <MultiTrigger.Conditions> <BindingCondition Binding="{Binding Source={x:Reference EmailValidator}, Path=IsValid}" Value="True" /> <BindingCondition Binding="{Binding Source={x:Reference FullNameValidator},Path=IsValid}" Value="True" /> </MultiTrigger.Conditions> <Setter Property="IsEnabled" Value="True" /> </MultiTrigger> </Button.Triggers> <!--</Style.Triggers> </Style>--> </Button>

Answers

  • RamprasadKRamprasadK USMember ✭✭
    Accepted Answer

    Here is my updated Code and its working.

    <Button Text="Create Data" IsEnabled="False" x:Name="CreateButton"> <!--<Style TargetType="Button"> <Style.Triggers>--> <Button.Triggers> <MultiTrigger TargetType="Button"> <MultiTrigger.Conditions> <BindingCondition Binding="{Binding Source={x:Reference EmailValidator}, Path=IsValid}" Value="True" /> <BindingCondition Binding="{Binding Source={x:Reference FullNameValidator},Path=IsValid}" Value="True" /> </MultiTrigger.Conditions> <Setter Property="IsEnabled" Value="True" /> </MultiTrigger> </Button.Triggers> <!--</Style.Triggers> </Style>--> </Button>

  • smhasansmhasan KWMember ✭✭

    **## Below is the final code for multi triggers to enabled and disabled button **

    MultiTrigger mt = new MultiTrigger(typeof(Button));
    BindingCondition bc = new BindingCondition()
    {
    Binding = new Binding("Text") { Path = "Text.Length", Source = txtMobile },
    Value = "8"
    };
    BindingCondition bc1 = new BindingCondition()
    {
    Binding = new Binding("Text") { Path = "Text.Length", Source = txtCardNumber },
    Value = "14"
    };
    mt.Conditions.Add(bc);
    mt.Conditions.Add(bc1);
    Setter st = new Setter()
    {
    Property = IsEnabledProperty,
    Value = true
    };
    mt.Setters.Add(st);
    button.Triggers.Add(mt);

  • MuthuramMuthuram Member ✭✭

    Hi @RamprasadK do u have any source for the multitrigger

Sign In or Register to comment.