1、LoginView.xaml.cs代码
//定义 提示信息
private string _errorMessage;
public string ErrorMessage
{
get { return _errorMessage; }
set
{
_errorMessage = value;
this.DoNotify();
}
}
//登录按钮-逻辑
private void DoLogin(object o)
{
this.ErrorMessage = "";
//判断用户名是否为空
if (string.IsNullOrEmpty(LoginModel.UserName))
{
this.ErrorMessage = "请输入用户名!";
return;
}
}
2、LoginView.xaml代码
<TextBlock Text="{Binding ErrorMessage}" Foreground="Red" Grid.Row="4" FontSize="13" TextWrapping="Wrap" LineHeight="22" HorizontalAlignment="Center"></TextBlock>
执行结果: