我有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