我正在开发一个UWP应用程序,其中我遵循MVVM模式。更新模型MVVM的ViewModel属性UWP
我有一个视图模型中的属性绑定到视图。我在处理多个任务的服务中有一个功能。
每次活动执行后,我需要更新视图模型中的属性。
ViewModel.cs
public Brush CurrentGetExecutionColor
{
get { return _currentGetExecutionColor; }
set { Set(ref _currentGetExecutionColor, value); }
}
public DelegateCommand DelegateCommandProcess
=> _delegateCommandProcess ?? (_delegateCommandProcess = new DelegateCommand(async() =>
{
await _service.ProcessMethod();
}));
Service.cs
private async Task<bool> ProcessMethod()
{
While(condition)
{
Process();
//UpdateViewModel property
CurrentGetExecutionColor = Color.Red;
}
}
我怎样才能实现这个功能,这样我可以从服务更新视图模型属性。
在此先感谢。
您正在寻找这样的:http://stackoverflow.com/questions/15439841/mvvm-in-wpf-how-to-alert -view-of-changes-in-model-or-should-i – Alex
您可以在模型上实现INotifyPropChanged,并让虚拟机订阅该模型。但这取决于很多细节,问题不是很完整。 –
我已更新我的帖子。你可以请看看。谢谢:) –