BusyIndi​​cator到datagrid

时间:2012-08-16 11:47:26

标签: c# wpf xaml

单击按钮我将数据加载到我的数据网格

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>

但指标不起作用,为什么?我该怎么做才能让它发挥作用?

3 个答案:

答案 0 :(得分:0)

对于我的WPF应用程序,我创建了自己的等待游标类

public class WaitCursor: IDisposable
{
    private Cursor _previousCursor;

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

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

并像这样称呼它

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

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

答案 1 :(得分:0)

在BusyIndi​​cator中设置 IsBusy =“True”将使其显示指示符。

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

答案 2 :(得分:0)

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

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