【发布时间】:2011-10-12 06:04:43
【问题描述】:
我有一个类似于 Outlook 的 WPF UI,左侧是导航,顶部是工具栏,底部是状态栏,所有这些都在 DockPanel 中。
应用程序的“主要”区域位于 DataGrid 内,即 LastChild,因此填充了剩余空间,目前看起来像这样:
<Grid DockPanel.Dock="Right">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<views:View1 Grid.Column="0" Grid.Row="0"/>
<views:View2 Grid.Column="0" Grid.Row="0"/>
<views:View3 Grid.Column="0" Grid.Row="0"/>
<views:View4 Grid.Column="0" Grid.Row="0"/>
</Grid>
这些视图都是具有自己的 ViewModel 的用户控件,其中 Visibility 属性绑定到其 ViewModel 中的属性并由导航窗格选择控制。 When a navigation pane item is selected the main ViewModel sends a message to ViewModels of the views and upon receiving the message the ViewModels of the views set their Visibility properties accordingly...
现在,这工作正常,但感觉不对,因为这些视图的所有 ViewModel 都是在应用启动时实例化的,而不是在选择相关导航窗格时提出有关性能和内存使用的问题...
My question is if there is a way of loading each view and its ViewModel "on demand", when the related navigation pane is selected and unloading these views and ViewModels when a different navigation pane is selected without resorting to PRISM/MEF or其他一些插件架构...更一般地说,您将如何构建这样一个在主视图中“嵌入”多个视图/ViewModel 的应用程序?
【问题讨论】: