【问题标题】:BusyIndicator to datagridBusyIndi​​cator 到数据网格
【发布时间】:2012-08-16 11:47:25
【问题描述】:

点击一个按钮,我将数据加载到我的数据网格中

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>

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

【问题讨论】:

  • 嗨,欢迎来到 SO!考虑使用比“不工作”更贴切的描述。什么不工作?它怎么不工作?你期待什么?

标签: c# wpf xaml


【解决方案1】:

对于我的 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;
}

【讨论】:

  • 在这种情况下,执行您的操作所需的时间非常短。寻找一些想法,比如运行一个非常大的数字循环并将其包围。
  • 数据加载 ~ 2-3 秒...正常吗?
【解决方案2】:

在 BusyIndi​​cator 中设置 IsBusy="True" 将使其显示指标。

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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

    • 对人好还是常识。第二,它实际上与@smhnkmr 的答案相同。它是伪代码,所以不要指望它在复制粘贴后工作。多想一点也无妨。
    猜你喜欢
    • 2011-03-15
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 2012-11-28
    • 2013-05-19
    • 2011-10-06
    • 1970-01-01
    相关资源
    最近更新 更多