Reputation: 31
I have a create-account page in my PCL, with a button that depends on several entry fields.
I want to enable the Create button only when the fields have the proper input. Here's my markup:
<Button Text="Create Account" Clicked="CreateAccountButton_Clicked" IsEnabled="False">
<Button.Triggers>
<MultiTrigger TargetType="Button">
<MultiTrigger.Conditions>
<BindingCondition Binding="{Binding Source={x:Reference EmailValidator}, Path=IsValid}" Value="True" />
<BindingCondition Binding="{Binding Source={x:Reference PasswordValidator}, Path=IsValid}" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="IsEnabled" Value="True" />
</MultiTrigger>
</Button.Triggers>
</Button>
I have verified that the validators are setting their IsValid properties to True, yet the button is NOT being enabled. I am using an Android emulator and Visual Studio 2019.
The code above is identical to several examples I found online.
Am I missing something?
Upvotes: 0
Views: 689
Reputation: 1
In your Xaml :
<ResourceDictionary>
<local:MultiTriggerConverter x:Key="DataHasBeenEnteredTrigger" />
</ResourceDictionary>
My Example :
<Button IsEnabled="False" Text="{localization:Translate login}" Margin="25,0" TextColor="{StaticResource color-fourth}" BackgroundColor="Yellow" Opacity="0.5" FontAttributes="Bold" Command="{Binding GoConnexionCommand}" >
<Button.Triggers>
<MultiTrigger TargetType="Button">
<MultiTrigger.Conditions>
<BindingCondition Binding="{Binding Source={x:Reference user},
Path=Text.Length,
Converter={StaticResource DataHasBeenEnteredTrigger}}"
Value="true" />
<BindingCondition Binding="{Binding Source={x:Reference password},
Path=Text.Length,
Converter={StaticResource DataHasBeenEnteredTrigger}}"
Value="true" />
</MultiTrigger.Conditions>
<Setter Property="IsEnabled" Value="True" />
<Setter Property="Opacity" Value="1" />
</MultiTrigger>
</Button.Triggers>
Convert Class:
public class MultiTriggerConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return false;
if ((int)value > 0) return true;
else return false; // Input is empty
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
Test this and tell me what it looks like!
Best regrads
Upvotes: 0