I am trying to have two entry that are numbers if they are numbers enable the button. If not enable the button. I created a sample app to test this.
What i tried so far created a class that checks if it is a double and changes the text to green if double or red if not. That works. I tried muititrgger conditions in the button. My thought was to check if the entry text color was red or green to control the button. I am placing my code below.
public class NumericValidationTriggerAction : TriggerAction<Entry>
{
protected override void Invoke (Entry entry)
{
double result;
bool isValid = Double.TryParse(entry.Text, out result);
entry.TextColor = isValid ? Colors.Black : Colors.Red;
}
}
<StackLayout>
<Label FontSize="20"
Text="EventTrigger Example"/>
<Label Text="Text must be a valid double or it will turn red"/>
<Entry x:Name="email"
Placeholder="Enter a System.Double"
>
<Entry.Triggers>
<EventTrigger Event="TextChanged">
<local:NumericValidationTriggerAction/>
</EventTrigger>
</Entry.Triggers>
</Entry>
<Button
Text="Save"
IsEnabled="False">
<Button.Triggers>
<MultiTrigger TargetType="Button">
<MultiTrigger.Conditions>
<BindingCondition Binding="{Binding Source={x:Reference email}, Path=Double.TryParse.email}" Value="Green"/>
</MultiTrigger.Conditions>
</MultiTrigger>
</Button.Triggers>
</Button>
</StackLayout>