views:

344

answers:

3

I've got an application based on Prism.

This is my shell:

<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>

In my MenuModule I add a view to the region and it shows fine:

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

The problem is: I don't want an ItemsControl in my shell, I want a ContentControl, but when I use a ContentControl, it shows nothing.

Why would ItemsControl show my views and ContentControl show nothing?

A: 

Could this be because a ContentControl will only display a single child, whereas an ItemsControl has multiple children?

I have't worked with Prism, but the API suggests that an IRegion is expected to have multiple children. If you're using a ContentControl then it is a little ambiguous what happens when I do the following:

IRegion mainRegion = this.regionManager.Regions["MainNavigationPanel"];
mainRegion.Add(new TestView());
mainRegion.Add(new SecondTestView());
Richard C. McGuire
The TestView will be shown, then the SecondTestView will be added, and then an exception may be risen. If not, then the behavior would be that you would never see the SecondTestView.
Rick
A: 

I noticed you are doing this in Initialize. Could be too early? Have you tried using registration rather than injection of your view to see if that changed anything?

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

This won't solve your problem, however it will prove that the problem is trying to add something before your region is actually available. RegisterViewWithRegion will delay the creation and display of the view until the region is available.

Anderson Imes
A: 

Unlike the ItemsControl with a ContentControl you also need to activate the view once you have added it to make it visible.

MainNavigationPresenter mainNavigationPresenter = this.container.Resolve<MainNavigationPresenter>();
IRegion mainRegion = this.regionManager.Regions["MainNavigationPanel"];
TestView view = new TestView()
mainRegion.Add(view);
mainRegion.Activate(view);
Kid Kaneda