我是MVVM的新手,我已经写了一个小应用程序来测试水和熟悉模式。我的应用程序的主要功能需要很长时间才能得到一些用户的反馈,表明这个过程还在继续。将调用放在单独的线程中并为进度条提供反馈的推荐方式是什么?函数的ViewModel代码如下所示。谢谢你的帮助。
public DataView Data
{
get
{
return resultsView;
}
set
{
if (value == resultsView)
{
return;
}
resultsView = value;
RaisePropertyChanged("Data");
}
}
private void SetData()
{
Data = RetrieveData.GetPartData(SelectedTeam, SelectedYear).DefaultView;
}
public RelayCommand GetData
{
get;
private set;
}
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel()
{
// Initializers for other part of ViewModel
// Teams = RetrieveData.GetTeams();
// Years = RetrieveData.GetYears();
GetData = new RelayCommand(SetData);
}发布于 2010-11-04 00:10:41
我还不是完全精通MVVM多线程,但这个链接似乎很可行:WPF Multithreading: Using the BackgroundWorker and Reporting the Progress to the UI.现在,我会尝试这样的东西:
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
Data = RetrieveData.GetPartData(SelectedTeam, SelectedYear).DefaultView;
};https://stackoverflow.com/questions/4086660
复制相似问题