我有Wpf窗口和相应的ViewModel
。有这势必财产CurrentActionTaken
使用委托从其他类更新wpf标签信息
private string _CurrentActionTaken;
public string CurrentActionTaken
{
get{
return _CurrentActionTaken;
}
set{
_CurrentActionTaken = value;
OnPropertyChanged("CurrentActionTaken");
}
}
我有一个BackgroundWorker
它调用私有方法WorkerDoWork
同一视图模型
_Worker = new BackgroundWorker();
...
_Worker.DoWork += (obj, e) => WorkerDoWork(_selectedEnumAction, _SelectedCountry);
_Worker.RunWorkerAsync();
Inside无WorkerDoWork
我想打电话给其他类将采取上MainWindow
标签努力工作,我想在我的MainWindow
标签上显示当前加工项目(绑定到CurrentActionTaken
属性)
private void WorkerDoWork(Enums.ProviderAction action, CountryCombo selCountry)
{
_CurrentActionTaken = "entered WorkerDoWork method";
OnPropertyChanged("CurrentActionTaken");
new MyOtherClass(_selectedEnumAction, _SelectedCountry);
...
}
这里我想使用这种方法,这将在OtherClass
数据迭代方法来调用:
public static void DataProcessUpdateHandler(string item)
{
MessageBox.Show(item);
}
终于从迭代某处OtherClass
拨打:
foreach (var item in items)
{
...
MainViewModel.DataProcessUpdateHandler(item.NameOfProcessedItem);
}
一切正常,里面显示项目MessageBox
in DataProcessUpdateHandler
MessageBox.Show(item);
我的问题是如何改变这一点,并使用
_CurrentActionTaken = item;
OnPropertyChanged("CurrentActionTaken");
现在这是不可能的原因DataProcessUpdateHandler
是静态方法。
谢谢,你能向我推荐任何更好的解决方案吗?(有我的问题),它可以更复杂一般但更容易维护。 – user1765862 2014-08-30 15:51:41
@ user1765862我已经编辑了我的答案和详细信息。 – Pragmateek 2014-08-30 16:08:13