0

我必须加载大数据,所以我决定busyIndicator在加载时使用。问题是,我显示加载数据文本,但它永远不会停止。

  public mainWindow()
        {
            InitializeComponent();
            rbi.IsBusy = true;
            Task.Factory.StartNew(getData);
        }


void getData()
        {

//method which loading data and inserting them into dataGrid
            Metoda();
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send,
                                       (Action)delegate
                                       {
                                           rbi.IsBusy = false;
                                       });

        }

BusyIndicator包括网格,所以它看起来像

<BusyIndicator>
<Grid>
<GridView>
....

@编辑:方法“方法”:

         void Metoda()
            {
            using (SqlConnection conn = new SqlConnection(cString.c_String))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("...", conn))
                {
//when entering there, it break and doesnt continue.
                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            needUpdate = rdr.GetBoolean(rdr.GetOrdinal("needUpdate"));
                        }
                    }
                }
            }
            if(needUpdate)
            {
    //loading data into static list of 'Product' type (read from DB using dataReader and add into static list - prodList)
                 FastSellSearchClass.GetProducts(wID);
            }
            GetProducts("", -1);
            }

            void GetProducts()
            {
            (...)
            //set itemssource = static list from previous method
            gridView.ItemsSource = FastSellSearchClass.prodList;
            }

@EDIT2:XAML 文件:

    <Grid>
            <my:BusyIndicator Name="rbi" IsIndeterminate="True">
                <my:GridView  IsReadOnly="True" Name="productsDG"  AutoGenerateColumns="False">
                    <my:GridView.Columns>
                       (...columns...)
                    </my:GridView.Columns>
                </my:GridView>
            </my:BusyIndicator>

        </Grid>
</Window>
4

1 回答 1

0

下面的代码对我有用。

 public Window2()
        {
            InitializeComponent();
            busyindicator1.IsBusy = true;
            Task.Factory.StartNew(CountTime);
        }

        public void CountTime()
        {
            for (int i = 0; i < 50; i++) //waiting for somthing.......
            {
                Thread.Sleep(100);
            }
            this.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
            {
                this.busyindicator1.IsBusy = false;
            }));
        }


  <Grid>
        <tk:BusyIndicator x:Name="busyindicator1" IsBusy="False">
        <TextBlock  Name="textBlock1" Text="Sample Window"  VerticalAlignment="Center" HorizontalAlignment="Center" />
        </tk:BusyIndicator>
    </Grid>
于 2013-06-20T14:29:19.003 回答