0

我有一个基于 Prism 的应用程序。

这是我的外壳:

<Window x:Class="AvarioCRM3.ShellV2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cal="http://www.codeplex.com/CompositeWPF" >

    <DockPanel LastChildFill="True">
        <Border
            Padding="10"
            DockPanel.Dock="Top"
            Background="#ddd">
            <DockPanel>
                <ItemsControl 
                    Name="MainNavigationPanel" 
                    cal:RegionManager.RegionName="MainNavigationPanel" 
                    DockPanel.Dock="Top"/>

            </DockPanel>
        </Border>
    </DockPanel>

</Window>

在我的MenuModule中,我向该区域添加了一个视图,它显示正常:

public void Initialize()
{
    MainNavigationPresenter mainNavigationPresenter = this.container.Resolve<MainNavigationPresenter>();
    IRegion mainRegion = this.regionManager.Regions["MainNavigationPanel"];
    mainRegion.Add(new TestView());
}

问题是:我不想在我的外壳中使用ItemsControl,我想要一个ContentControl,但是当我使用 ContentControl 时,它什么也没有显示。

为什么 ItemsControl 会显示我的视图而 ContentControl 什么也不显示?

4

3 回答 3

1

与带有 ContentControl 的 ItemsControl 不同,您还需要在添加视图后激活视图以使其可见。

MainNavigationPresenter mainNavigationPresenter = this.container.Resolve<MainNavigationPresenter>();
IRegion mainRegion = this.regionManager.Regions["MainNavigationPanel"];
TestView view = new TestView()
mainRegion.Add(view);
mainRegion.Activate(view);
于 2010-01-02T16:01:18.020 回答
1

这可能是因为 ContentControl 只会显示一个孩子,而 ItemsControl 有多个孩子吗?

我没有使用过 Prism,但 API 建议 IRegion 应该有多个孩子。如果您使用的是 ContentControl,那么当我执行以下操作时会发生什么有点模棱两可:

IRegion mainRegion = this.regionManager.Regions["MainNavigationPanel"];
mainRegion.Add(new TestView());
mainRegion.Add(new SecondTestView());
于 2009-07-22T12:18:52.950 回答
0

我注意到您在 Initialize 中执行此操作。会不会太早了?您是否尝试过使用注册而不是注入您的视图来查看是否改变了什么?

regionManager.RegisterViewWithRegion("MainNavigationPanel", typeof(TestView));

这不会解决您的问题,但是它将证明问题是在您的区域实际可用之前尝试添加一些东西。RegisterViewWithRegion 将延迟视图的创建和显示,直到区域可用。

于 2009-07-22T15:44:41.150 回答