编辑长度验证xamarin表格

问题描述 投票:0回答:1

我想对这个编辑器做一些验证,例如“编辑器不能为空写东西”。我可以验证输入<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>
validation xaml xamarin editor
1个回答
2
投票

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

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

Xamarin也有关于做Validation in MVVM的广泛文章

© www.soinside.com 2019 - 2024. All rights reserved.