编辑器长度验证 xamarin 表单

editor length validation xamarin forms

我想对这个编辑器做一些验证,例如"editor can not be empty write something"。我可以验证为输入 < 0,但是,我将需要此验证才能转到下一页。有任何想法吗 ?谢谢。 这是我的xaml。

     <StackLayout Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3">
                        <Label Text="Description" FontSize="Medium" Style="{StaticResource LabelStyle}" />
                        <Editor x:Name="Description" FontSize="Medium" HeightRequest="120" TextChanged ="Handle_TextChanged" />
<Label x:Name ="Errorlabel"/>
                    </StackLayout>

cs:

 async void Send_Activated(object sender, System.EventArgs e)
        {
            var editor = EDescription.Text;

            if (string.IsNullOrWhiteSpace (editor))
            {
                Errorlabel.Text = "Plase add a description ";
                ToolbarItems.Clear();

            }

            if (editor.Length >1)
            {
                await App.Navigator.PushAsync(new 2View());  
            }
      }

工具栏:

<ContentPage.ToolbarItems>
        <ToolbarItem  x:Name = "anySend" Text="Send" Order="Primary" Activated="Send_Activated"  />
    </ContentPage.ToolbarItems>

验证非空条目的简单方法:

if (string.IsNullOrEmpty(Description.Text)) {
    DisplayAlert("Error","Please enter a description", "OK");
} else {
    Navigation.PushAsync(nextPage);
}

Xamarin 也有大量关于 Validation in MVVM

的文章