2012-08-16 39 views
-3

上点击一个按钮,我将数据加载到数据网格我BusyIndi​​cator控件到数据网格

MySqlCommand cmd1m = new MySqlCommand("select * from table", conn); 
DataTable dt1m = new DataTable(); 
dt1m.Load(cmd1m.ExecuteReader()); 
System.Windows.Forms.BindingSource source = new System.Windows.Forms.BindingSource(); 
source.DataSource = dt1m; 
dataGrid1.ItemsSource = source; 

命名空间:

xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended" 

和XAML:

<wpf:BusyIndicator Name="loading" IsBusy="False"> 
<DataGrid>...</DataGrid> 
</<wpf:BusyIndicator> 

但指标没有工作,为什么?我应该怎么做才能使它工作?

+2

嗨,欢迎来到SO!考虑使用比“不工作”更贴切的描述。什么不起作用?它怎么不起作用?你能指望什么? – 2012-08-16 11:50:01

回答

0

对于我的WPF应用程序我已经创建了自己的等待光标类

public class WaitCursor: IDisposable 
{ 
    private Cursor _previousCursor; 

    public WaitCursor() 
    { 
     _previousCursor = Mouse.OverrideCursor; 
     Mouse.OverrideCursor = Cursors.Wait; 
    } 

    pubic void Dispose() 
    { 
     Mouse.OverrideCursor = _previousCursor; 
    } 
} 

,并调用它

//Some code for which you do not want wait cursor 
//.... 

using(new WaitCursor()) 
{ 
    dataGrid1.ItemsSource = source; 
} 
+0

不起作用,光标不是“等待” – 2012-08-16 12:05:00

+0

在这种情况下,执行操作所需的时间非常短。寻找一些想像运行一个非常大的数字环绕它。 – 2012-08-16 12:07:22

+0

数据加载〜2-3秒...正常? – 2012-08-16 12:18:00

0

设置IsBusy =“真”在BusyIndi​​cator控件将使它秀指标。

在您的情况下,将布尔值属性绑定到IsBusy,并在加载数据时将其设置为True。加载完成后,将其设为False。

0

执行操作时,应该切换“IsBusy”属性。

loading.IsBusy = true; 
    // ... perform actions ... 
    loading.IsBusy = false; 
+0

对人们很好,这仍然是常识。第二,它跟@smhnkmr几乎是一样的答案。这是伪代码,所以不要指望它在复制粘贴后工作。想一点点就没有害处。 – KyorCode 2012-08-16 13:41:29

相关问题