我必须加载大数据,所以我决定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>