我有一个ListView,我需要它定期调用数据库并显示一小组数据...我希望只是在XAML页面后面的代码中执行它。
private readonly BackgroundWorker mWorker = new BackgroundWorker();
private object m_lock = new object();
ObservableCollection<Request> mNames = new ObservableCollection<Request>();
public SettingsControl()
{
InitializeComponent();
//LoadData();
BindingOperations.EnableCollectionSynchronization(mNames, m_lock);
mWorker.DoWork += LoadData;
mWorker.RunWorkerAsync();
}
public void LoadData(object sender, DoWorkEventArgs e)
{
while (true)
{
BindingOperations.EnableCollectionSynchronization(mNames, m_lock);
var db = new Database();
var pendinglist = db.ReturnPendingUser();
mNames.Clear();
foreach (var user in pendinglist)
{
mNames.Add(user);
}
lvDataBinding.ItemsSource = mNames;
}
Thread.Sleep(2000);
}
我尝试使用后台工作程序来调用数据库并重新加载数据表但没有运气。
请咨询
答案 0 :(得分:0)
基本上是user1672994提到的 我需要放置lvDataBinding.ItemsSource = mNames;在默认构造函数上。