如何更新棱镜区域中的当前视图
How to update cuurent view in prism region
我想知道有没有办法在棱镜区域加载后更新我当前的视图。
我的视图在加载时自动更新,每次调用时我都使用生命周期界面加载。
有没有办法像更新文件夹一样更新当前视图??
首先,视图模型(及其视图)应该在模型更改时自动更新,可以通过 INotifyPropertyChanged
、专用事件、使用 EventAggregator
或任何其他方式消息传递系统。
也就是说,如果您希望视图模型仅在某个时间点更新(例如,当用户单击更新按钮时),您应该将更新代码移出 NavigatedTo
方法并从 NavigatedTo
和 UpdateCommand
.
调用该方法
internal class MyViewModel : BindableBase, INavigationAware
{
public MyViewModel( IDataSource theSourceOfData )
{
_theSourceOfData = theSourceOfData;
UpdateCommand = new DelegateCommand( UpdateData );
}
public string MyProperty
{
get
{
return _myProperty;
}
set
{
SetProperty( ref _myProperty, value );
}
}
public DelegateCommand UpdateCommand { get; }
#region INavigationAware
public void OnNavigatedTo( NavigationContext navigationContext )
{
UpdateData();
}
#endregion
#region private
private readonly IDataSource _theSourceOfData;
private string _myProperty;
private void UpdateData()
{
_myProperty = _theSourceOfData.FetchTheData();
}
#endregion
}
现在,如果我们单击更新按钮,MyViewModel.MyProperty
将更新并将更改通知推送到视图。如果我们导航到视图模型,也会发生同样的情况。
我想知道有没有办法在棱镜区域加载后更新我当前的视图。 我的视图在加载时自动更新,每次调用时我都使用生命周期界面加载。 有没有办法像更新文件夹一样更新当前视图??
首先,视图模型(及其视图)应该在模型更改时自动更新,可以通过 INotifyPropertyChanged
、专用事件、使用 EventAggregator
或任何其他方式消息传递系统。
也就是说,如果您希望视图模型仅在某个时间点更新(例如,当用户单击更新按钮时),您应该将更新代码移出 NavigatedTo
方法并从 NavigatedTo
和 UpdateCommand
.
internal class MyViewModel : BindableBase, INavigationAware
{
public MyViewModel( IDataSource theSourceOfData )
{
_theSourceOfData = theSourceOfData;
UpdateCommand = new DelegateCommand( UpdateData );
}
public string MyProperty
{
get
{
return _myProperty;
}
set
{
SetProperty( ref _myProperty, value );
}
}
public DelegateCommand UpdateCommand { get; }
#region INavigationAware
public void OnNavigatedTo( NavigationContext navigationContext )
{
UpdateData();
}
#endregion
#region private
private readonly IDataSource _theSourceOfData;
private string _myProperty;
private void UpdateData()
{
_myProperty = _theSourceOfData.FetchTheData();
}
#endregion
}
现在,如果我们单击更新按钮,MyViewModel.MyProperty
将更新并将更改通知推送到视图。如果我们导航到视图模型,也会发生同样的情况。