【发布时间】:2019-04-10 00:12:28
【问题描述】:
我有一个包含可观察集合属性的视图模型:
public ObservableCollection<ExplorerPane> Panes { get; set; } = new ObservableCollection<ExplorerPane>();
在与我的视图模型对应的用户控件中,我使用Panes 作为ItemsSource 到ItemsControl,并且只使用ContentPresenter 来显示每个ExplorerPane 的内容:
<ItemsControl ItemsSource="{Binding Panes}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
问题是我希望内容演示者将他们的窗格在彼此的顶部呈现,这样一次只有一个可见。
然后我的问题是如何让内容演示者位于网格的同一个单元格中?
【问题讨论】:
-
如果您只想显示单个 ExplorerPane,请将
CurrentPane属性添加到您的视图模型中,并通过<ContentControl Content={Binding CurrentPane}"/>显示它 -
这个建议有效;如果您更新答案,我会将其标记为已接受。