c# - Xamarin 表单上的 ActivityIndicator
问题描述
如何将 ActivityIndicator 放在 Xamarin Forms OnStart() 函数上。我正在检查 OnStart() 函数的网络访问。
解决方案
将 ActivityIndicator 绑定到 BaseViewModel (IsBusy) 中的属性。
看法
<ActivityIndicator Color="Accent" IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}" />
BaseViewModel(由所有 ViewModel 继承)
private bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
set
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
为自己准备一个好的 MVVM 框架(Prism),并将网络检查放在起始页的 OnNavigatedTo 方法中。
public override void OnNavigatedTo(INavigationParameters parameters)
{
IsBusy = true;
await CheckNetwork();
IsBusy = false;
}
现在,您可以将相同的 ActivityIndicator 片段粘贴到绑定到继承 BaseViewModel 的 ViewModel 的任何页面 (XAML) 中,并且它只会在您设置 IsBusy 时工作。
推荐阅读
- c# - 包含货币值的输入字段的客户端验证错误
- docker - docker 被杀后 consul docker 无法持久化数据
- pysimplegui - pysimpleguiweb 更改托管端口
- ruby-on-rails - ActiveRecord 嵌套关联
- sql - 如何在标准 SQL BigQuery 中解析 JSON?
- vb.net - 新加入的数组缺少一个元素 - vb
- r - 是否可以定义一个“函数”并将其插入“公式”以在 R 中构造一个“model.frame”?
- r - 使用“setkey”函数将表与 R 中的常用值连接起来
- prisma - Prisma.io 多对多关系会产生错误
- python - Python iter 函数在没有正常函数的标记值的情况下无法工作