
该工具包可通过NuGet方便地获得,这使得将其添加为项目的参考非常容易.我几乎在所有最近的WPF项目中都亲自使用过它(以及该工具包中的许多其他有用的控件).
要使用它,请使用忙指示符在XAML代码中围绕控件:
<extToolkit:BusyIndicator ...>
<Grid>
<Button Content="Click to do stuff" />
<!-- your other stuff here -->
</Grid>
</extToolkit:BusyIndicator>
Run Code Online (Sandbox Code Playgroud)
然后,您只需将IsBusy属性设置为true您希望弹出窗口显示的位置,并将其设置为false,以便隐藏它.在适当的MVVM体系结构中,您通常会将XAML中的属性数据绑定到viewmodel中的属性,然后将其设置为true/false:
<extToolkit:BusyIndicator IsBusy="{Binding IsBusy}" >
Run Code Online (Sandbox Code Playgroud)
但是如果你没有使用MVVM,你当然可以从你的代码中手动设置它,通常是在按钮点击处理程序中:
为控件命名,以便能够从代码中引用它:
<extToolkit:BusyIndicator x:Name="busyIndicator" >
Run Code Online (Sandbox Code Playgroud)
然后,在您的xaml.cs文件中:
void myButton_Click(object sender, RoutedEventArgs e)
{
busyIndicator.IsBusy = true;
// Start your background work - this has to be done on a separate thread,
// for example by using a BackgroundWorker
var worker = new BackgroundWorker();
worker.DoWork += (s,ev) => DoSomeWork();
worker.RunWorkerCompleted += (s,ev) => busyIndicator.IsBusy = false;
worker.RunWorkerAsync();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3990 次 |
| 最近记录: |