将BusyIndicator放入子窗口实现公用
为了 让进度条实现简单的公用,把它放到了一个子窗口(childwindow)中,
- C# code
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 ); }); } }然后 在一个工具类里 写了此窗口的
打开 和关闭事件(BeginWaiting 和 EndWaiting)
- C# code
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(); }现在的问题时,在别的silverlight窗口中,异步调用BeginWaiting() 和 EndWaiting() 后,子窗口是关了,但是原父窗口依然是置灰和不可操作状态,好像子窗口依然没有关一样,怎么回事儿啊 ???大神们帮帮忙 指点一下。
GetBusyForm().Close();改为GetBusyForm().DialogResult = false;也不行,怎么办呢?
[解决办法]
相对其他控件而言,进度条控件不占用太多资源,通常来说,只需要将进度条的模板进行公共管理就可以了,如果有页面调用,只需独立设置就可以。
个人而言,不推荐将进度条放在childwindows中使用,会降低应用效率。