Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要在Xamarin中的条目中输入值_C#_.net_Xamarin_.net Core_Xamarin.forms - Fatal编程技术网

C# 需要在Xamarin中的条目中输入值

C# 需要在Xamarin中的条目中输入值,c#,.net,xamarin,.net-core,xamarin.forms,C#,.net,Xamarin,.net Core,Xamarin.forms,在我的应用程序中,有一个多条目和按钮 我想要的是条目不应该为空,如果为空,则按钮将不起作用。e、 就像HTML中的必需属性一样 我问了一些类似的问题,但这个解决方案在条目上不起作用 视图中的输入和按钮代码 <Entry Text="{Binding Email}" Keyboard="Email" ReturnType="Done" Placeholder="Enter Email&quo

在我的应用程序中,有一个多
条目
按钮

我想要的是
条目
不应该为空,如果为空,则
按钮
将不起作用。e、 就像HTML中的必需属性一样

我问了一些类似的问题,但这个解决方案在
条目上不起作用

视图中的输入和按钮代码

<Entry
    Text="{Binding Email}"
    Keyboard="Email"
    ReturnType="Done"
    Placeholder="Enter Email">
</Entry>

<Entry
    Text="{Binding Password}"
    Keyboard="Numeric"
    IsPassword="true"
    ReturnType="Done"
    Placeholder="Enter Password">
</Entry>

<Button
    Text="Submit"
    Command="{Binding FormDataButtonCommand}"/>
#region Bindable Command
public ICommand FormDataButtonCommand => new Command(async () => await FormDataButton(default, default));
#endregion

#region Bindable Properties
private string _Email;
public string Email
{
get => _Email;
set => this.RaiseAndSetIfChanged(ref _Email, value);
}

private string _Password;
public string Password
{
get => _Password;
set => this.RaiseAndSetIfChanged(ref _Password, value);
}

ICommand
构造函数cat获取第二个参数。您应该使用它来启用/禁用命令:

public ICommand FormDataButtonCommand { get; set; } 
...
FormDataButtonCommand = new Command(FormDataButton, CanFormData); // in ctor

public bool CanFormData(object obj)
{
     return !string.IsNullOrWhiteSpace(Email) && !string.IsNullOrWhiteSpace(Password);
}


private async void FormDataButton(object obj)
{
    // your logic here
}

您可以对其他值执行此操作,例如Button.TextColor代替假返回颜色。灰色代替真返回颜色。黑色。类似这样的东西。

我真的很喜欢并使用了很多
当任何…
可观察的
和所有很酷的反应性东西

但是正如@Miamy所说的那样,该命令将以这种方式禁用,但是如果您想更改颜色或样式,我将以这种方式执行

<Entry
    Text="{Binding Email}"
    Keyboard="Email"
    ReturnType="Done"
    Placeholder="Enter Email">
</Entry>

<Entry
    Text="{Binding Password}"
    Keyboard="Numeric"
    IsPassword="true"
    ReturnType="Done"
    Placeholder="Enter Password">
</Entry>

<Button
    Text="Submit"
    IsEnabled="{Binding IsButtonEnabled}"
    Command="{Binding FormDataButtonCommand}"/>
我不喜欢这样做,但这是更简单的方法。。。国际海事组织


不必启用
IsButtonEnabled
setter,此属性只能有一个getter。在这种情况下,
IsButtonEnabled
应该在
Email
Password
设置器中提出。修复了
Email
setter
@Miamy,是的,我们只能使用
getter
并在
Email
Password
设置器中提出,以便用作“
私有
”而不是
绑定
双向
,但我认为这种方式更具可读性或
属性
用户友好:)@jjchiw,在这种情况下,最好使用
IsButtonEnabled=!string.IsNullOrEmpty(值)&&!IsNullOrEmpty(电子邮件)
在一个地方,从我们需要的所有setter调用它(将来我们可能需要检查first/lastname、phone等)@jjchiw嗨,我陷入了这个问题,你能看一下吗,你会很好:)=>on
async()=>wait FormDataButton(默认,默认)
返回错误
CS1593:委托“操作”不接受0个参数。
您的意思是它没有编译还是没有按计划工作?没有编译。。因为正如你所说,把
FormDataButtonCommand=new命令(FormDataButton,CanFormData)在构造函数中,我做到了。。它会把它标记为红色。那么你的错误是什么呢?这个代码段应该可以工作,我使用过很多次,在xamarin中也是如此:)在构造函数中,我编写了
FormDataButtonCommand=new命令(FormDataButton(default,default),CanFormData)它说
CS503:参数1:无法从“System.Threading.Tasks.Task”转换为“System.Action”
public class AnyNullValueCheckConverter: IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values == null)
        {
            return false;
        }

        foreach (var value in values)
        {
            if (value is string str && string.IsNullOrEmpty(str))
            {
                return false;
            }
        }
        return true;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
       throw new NotImplementedException();
    }
}
<Entry
    Text="{Binding Email}"
    Keyboard="Email"
    ReturnType="Done"
    Placeholder="Enter Email">
</Entry>

<Entry
    Text="{Binding Password}"
    Keyboard="Numeric"
    IsPassword="true"
    ReturnType="Done"
    Placeholder="Enter Password">
</Entry>

<Button
    Text="Submit"
    IsEnabled="{Binding IsButtonEnabled}"
    Command="{Binding FormDataButtonCommand}"/>
private string _Email;
public string Email
{
 get => _Email;
 set {
    IsButtonEnabled = !string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(Password);
    this.RaiseAndSetIfChanged(ref _Email, value);
  }
}

private string _Password;
public string Password
{
 get => _Password;
 set {
    IsButtonEnabled = !string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(Email);
  this.RaiseAndSetIfChanged(ref _Password, value);
  }
}

private bool _IsButtonEnabled;
public bool IsButtonEnabled
{
 get => _IsButtonEnabled;
 set => this.RaiseAndSetIfChanged(ref _IsButtonEnabled, value);
}