我在PCL中有一个创建帐户页面,其中有一个取决于多个输入字段的按钮。
我只想在字段具有正确的输入时启用“创建”按钮。这是我的标记:
<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>
我已验证验证器将其IsValid属性设置为True,但尚未启用该按钮。我正在使用Android模拟器和Visual Studio 2019。
上面的代码与我在网上找到的几个示例相同。
我想念什么吗?
答案 0 :(得分:0)
在您的Xaml中:
<ResourceDictionary>
<local:MultiTriggerConverter x:Key="DataHasBeenEnteredTrigger" />
</ResourceDictionary>
我的例子:
<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>
转换班级:
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();
}
}
测试一下,然后告诉我它是什么样子!
最佳成绩