将BusyIndicator放入子窗口实现公用
为了 让进度条实现简单的公用,把它放到了一个子窗口(childwindow)中,
public partial class SLW44ShowBusy : ChildWindow { public SLW44ShowBusy() { InitializeComponent(); this.Loaded += new RoutedEventHandler(SLW44ShowBusy_Loaded); this.Closed += new EventHandler(SLW44ShowBusy_Closed); } void SLW44ShowBusy_Closed(object sender, EventArgs e) { SearchFinish(); } void SLW44ShowBusy_Loaded(object sender, RoutedEventArgs e) { SearchBegin(); } public void SearchBegin() { this.pingbi.Visibility = Visibility.Visible;//显示 busyIndicator1.IsBusy = true; //打开进度条 } public void SearchFinish() { //关闭进度条 ThreadPool.QueueUserWorkItem((threadState) => { Dispatcher.BeginInvoke(() => busyIndicator1.IsBusy = false ); Dispatcher.BeginInvoke(() => this.pingbi.Visibility = Visibility.Collapsed ); }); } }
private static SLW44ShowBusy showBusyForm = null; private static SLW44ShowBusy GetBusyForm() { if (showBusyForm == null) { showBusyForm=new SLW44ShowBusy(); } return showBusyForm; } //显示等待窗口 public static void BeginWaiting() { GetBusyForm().Show(); } public static void EndWaiting() { GetBusyForm().Close(); }