【发布时间】:2021-10-18 05:07:27
【问题描述】:
我有一个设置为最大长度 3 的条目。当用户尝试输入 4 个字符时,我想显示一个简单的 DisplayAlert 消息,如 here 所示。我正在尝试使用 MVVM 实现它,但很难绑定警报所需的等待。我知道如果有帮助,最大长度将始终为 3。
Xaml:
<Entry Text = "{Binding BoundText}"/>
视图模型:
string _boundText;
public string BoundText
{
get => _boundText;
set
{
if(value.Length > 3)
{
await DisplayAlert("Alert", "You have been alerted", "OK");
}
else
{
...
}
}
}
我得到的错误是 await 运算符需要在 async 方法中,但是当我添加它时,我得到一个错误,即修饰符 async 对构造函数无效。关于如何实现这一点的任何想法?
【问题讨论】:
标签: c# xamarin mvvm async-await binding