【发布时间】:2021-02-25 10:09:45
【问题描述】:
我在 Xamarin 应用程序中的 Button 上使用 IsEnabled,但有两件事我不能做。
- 把
TextColor改成IsEnabled = false,但是我可以改BackgroundColor。
解决方案是使用自定义条目,有一篇很棒的文章 => https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/entry
但它只适用于:
public class MyEntry : Entry
{
}
我的页面背后的代码是:
public class MyEntry : ContentPage
{
}
而且我不能使用多个类。有没有办法在 xml.cs 页面中使用Entry 和ContentPage?
- 我只想在
IsEnabled = true时启用Command,例如ViewModel 中的ICommand只有在IsEnabled值为true时才有效。
完整的代码示例 => https://stackoverflow.com/a/64808306/14139029
.xml
<Button
x:Name="PasswordButton"
IsEnabled="False"
TextColor="#4DABFE"
BackgroundColor = "#FFFFFF"
Text="Submit"
Command={Binding PasswordButtonCommand}>
</Button>
.xml.cs
if (Password.Text == ConfirmPassword.Text)
{
PasswordButton.IsEnabled = true;
PasswordButton.TextColor = Color.FromHex("004B87");
PasswordButton.BackgroundColor = Color.FromHex("222222");
}
【问题讨论】:
标签: c# .net xamarin xamarin.forms