我在一个框架内的页面需要时间来加载,这意味着控件第一次出现在页面上需要一些时间。我应该在我的主 window.cs 文件中的哪个位置设置 IsBusy = true。我不知道如何使用忙碌指示器。我应该何时将其切换为 true 或 false。请指导我应该如何使用它?提前致谢。
5047 次
2 回答
3
通常,您会在开始执行大量繁重处理之前设置繁忙指示器,这取决于您的代码。
它通常会在您生成后台线程以执行大量工作之前让 UI 说它目前很忙,当线程完成时,然后“不忙” UI。
于 2015-09-03T15:03:46.983 回答
2
Xaml
用忙碌的指示器包裹你。假设您正在使用MVVM
<xctk:BusyIndicator BusyContent="{Binding BusyText}" IsBusy="{Binding IsBusy}">
<Grid>
<!--Your controls and content here-->
</Grid>
</xctk:BusyIndicator>
在你的viewmodel
/// <summary>
/// To handle the Busy Indicator's state to busy or not
/// </summary>
private bool _isBusy;
public bool IsBusy
{
get
{
return _isBusy;
}
set
{
_isBusy = value;
RaisePropertyChanged(() => IsBusy);
}
}
private string _busyText;
//Busy Text Content
public string BusyText
{
get { return _busyText; }
set
{
_busyText = value;
RaisePropertyChanged(() => BusyText);
}
}
命令和命令处理程序
//A Command action that can bind to a button
private RelayCommand _myCommand;
public RelayCommand MyCommand
{
get
{
return _myCommand??
(_myCommand= new RelayCommand(async () => await CommandHandler(), CanExecuteBoolean));
}
}
internal async Task CommandHandler()
{
Isbusy = true;
BusyText = "Loading Something...";
Thread.Sleep(3000); // Do your operation over here
Isbusy = false;
}
于 2015-09-17T10:09:23.357 回答