【发布时间】:2017-12-18 18:37:35
【问题描述】:
我有一个包含一个窗口的 WPF 应用程序。只有抛出这个窗口,用户才能在应用程序中执行他的导航。
应用结构为:
- MainWindow.xaml
- MainWindowViewModel.cs
- StartPage.xaml
- StartPageViewMode.cs
- Systems.xaml
- Systems.cs
- 其他视图和相关视图模型。
MainWindow.xaml
<Grid>
<ContentControl Content="{Binding CurrentWorkspace}" x:Name="ContentControlMainWindow" VerticalAlignment="Stretch"/>
</Grid>
MainWindowViewModel.cs
private ContentControl _currentWorkspace;
public ContentControl CurrentWorkspace
{
get => _currentWorkspace;
set => SetProperty(ref _currentWorkspace, value);
}
//c'tor
public MainWindowViewModel()
{
CurrentWorkspace.Content = new ContentControl { Content = new StartPage()
}
如您所见,在应用程序初始化时,我将 StartPage 视图加载到 CurrentWorkspace。 现在从 StartPageViewModel 我需要将 CurrentWorkspace 内容更改为另一个视图。 基本上我很难从应用程序的每个部分控制(和更改)这个 CurrentWorkspace。
【问题讨论】:
-
查看 WPF 中的导航概念。
标签: c# wpf mvvm binding contentcontrol