我想对这个编辑器做一些验证,例如“编辑器不能空写东西”。我可以验证输入<但是,我需要进行此验证才能进入下一页。有任何想法吗 ?谢谢。 这是我的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>
答案 0 :(得分:2)
验证非空条目的简单方法:
if (string.IsNullOrEmpty(Description.Text)) {
DisplayAlert("Error","Please enter a description", "OK");
} else {
Navigation.PushAsync(nextPage);
}
Xamarin还有关于Validation in MVVM
的广泛撰写