我必须加载大数据,所以我决定在加载时使用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>
....@EDIT: Metod "Metoda":
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>发布于 2013-06-20 22:29:19
下面的代码对我来说很有效。
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>https://stackoverflow.com/questions/17216027
复制相似问题