ViewModel 更改时窗口不会更新
我有一个使用 MVVM 的 WPF 应用程序;当我更改主窗口 ViewModel 类中的 ViewModel 时,新的用户控件不会显示在窗口中...原始用户控件仍然存在。 ViewModel 看起来像这样:
公共类 MainWindowViewModel :ViewModelBase {
public ViewModelBase Workspace;
public MainWindowViewModel()
{
var w = new CustomerDetailsViewModel();
SetActiveWorkspace(w);
}
void NavigationService_ViewChanged(object sender, ViewChangedEventArgs e)
{
SetActiveWorkspace(e.View);
}
void SetActiveWorkspace(ViewModelBase workspace)
{
Workspace = workspace;
}
}
我的 XAML 如下所示: <代码> < ContentControl Content="{绑定路径=工作区}" > 导航服务 ViewChanged 事件正在触发,并且
正在使用参数中的正确视图调用 SetActiveWorkspace 方法。但是,此后,视图不会重新加载。我在这里缺少什么?
I have a WPF application using MVVM; when I change the ViewModel in my main window ViewModel class, the new user control is not displayed in the window... the original one remains. The ViewModel looks like this:
public class MainWindowViewModel : ViewModelBase
{
public ViewModelBase Workspace;
public MainWindowViewModel()
{
var w = new CustomerDetailsViewModel();
SetActiveWorkspace(w);
}
void NavigationService_ViewChanged(object sender, ViewChangedEventArgs e)
{
SetActiveWorkspace(e.View);
}
void SetActiveWorkspace(ViewModelBase workspace)
{
Workspace = workspace;
}
}
My XAML looks like this:
< ContentControl Content="{Binding Path=Workspaces}" >
The navigation service ViewChanged event is firing, and the SetActiveWorkspace method is being called with the correct view in the argument. However, after that, the view is not reloaded. What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的工作区属性未引发 PropertyChanged 事件。它应该看起来像这样:
确保您的 ViewModelBase 实现了
INotifyPropertyChanged
Your Workspace property is not raising the PropertyChanged event. It should look like this:
Make sure your ViewModelBase implements
INotifyPropertyChanged