Region inside the view loading in region

Topics: Prism v4 - Silverlight 4
Aug 3, 2012 at 3:03 AM

Hi Friends out there.

I have a view which i am loading in the region of my shell. Its works fine.But i also need the region within my loaded view .For that i created region inside my view nut when i try to get through region-manger it is unable to find.

So please find how to do this that.

Here is my shell.

 

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             
    xmlns:Region="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:ee="http://schemas.microsoft.com/expression/2010/effects" x:Class="NewHappyNagarCompletePrism.HappyNagar"
    mc:Ignorable="d"
             
    d:DesignHeight="626" d:DesignWidth="894">
	<UserControl.Background>
		<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
			<GradientStop Color="#FF412541" Offset="0.073"/>
			<GradientStop Color="#FF916969" Offset="1"/>
		</LinearGradientBrush>
	</UserControl.Background>
    <ScrollViewer>
        <Grid x:Name="LayoutRoot" Height="900" Opacity="0.995" RenderTransformOrigin="0.261,0.243">
        	<Grid.Background>
        		<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
        			<GradientStop Color="#FF3A3D45" Offset="0.108"/>
        			<GradientStop Color="#FF0E0502"/>
        			<GradientStop Color="Black" Offset="0.927"/>
        		</LinearGradientBrush>
        	</Grid.Background>
        
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
                <RowDefinition Height="56" />
                <RowDefinition Height="*" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
        
       
            <ItemsControl Region:RegionManager.RegionName="MainRegion" VerticalAlignment="Center"  Grid.Row="2"  />
            
 
            <ItemsControl Region:RegionManager.RegionName="MenuRegion" VerticalAlignment="Top"  Grid.Row="1"/>
 
            <TextBlock Margin="416,0,269,12" x:Name="textBlock1"  Foreground="#FF3DAD62" FontFamily="Lucida Bright" FontSize="32" d:LayoutOverrides="Width" >
              	<TextBlock.Effect>
              		<DropShadowEffect Color="#FF643232"/>
              	</TextBlock.Effect>
              	<TextBlock.Projection>
              		<PlaneProjection RotationX="-1"/>
              	</TextBlock.Projection>
              </TextBlock>
            
 
        </Grid>
    </ScrollViewer>
</UserControl>


Here is my View which gets loaded in MainRegion.

<UserControl x:Class="ABC.Views.XYZ"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
             xmlns:Command="clr-namespace:Microsoft.Practices.Prism.Commands;assembly=Microsoft.Practices.Prism"
xmlns:Region="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism"
    d:DesignHeight="300" d:DesignWidth="400"
            
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
 
    <Grid x:Name="LayoutRoot" Background="Green" Height="700"  >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="116*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <ItemsControl Region:RegionManager.RegionName="ChartDetails" VerticalAlignment="Top" ></ItemsControl>
        <ItemsControl Region:RegionManager.RegionName="MainChart" VerticalAlignment="Top" Grid.Column="1"></ItemsControl>
    </Grid>
</UserControl>
 

When i do to get Chartdetails region .Region Manager not able to find it.

 
 IRegion region = _region.Regions["ChartDetails"];
  region.Add(_container.Resolve<NodeView>(),"Node");


So please tell me how to do that and what wrong i am doing.

Thanks in advance.

Developer
Aug 3, 2012 at 2:35 PM

Hi,

So far, I couldn't find anything wrong within the code snippets you provided. It would be helpful if you could provide us with more information about your scenario so we can help you further with this. Particularly, it could help us to now, how you are loading your "XYZ" view in your "MainRegion". Also, I believe you could check that the timing when adding each view is in the right order.

Regards,

Agustin Adami
http://blogs.southworks.net/aadami

Aug 4, 2012 at 11:55 AM

Hi Thanks for reply.

 

In my scenario is that in my view which loads in "MainRegion" will have 2 more region  and in those two region there will be two functionality on that view and

content of these region will be changed.

So for that i need to get these region so that i can load my different view in this nested region.

So please tell me how to do this.

Developer
Aug 6, 2012 at 2:43 PM
Edited Aug 6, 2012 at 2:50 PM

Hi,

Based on my understanding of the scenario you described you should be able to get the nested region without problems. I created a small sample based on the code snippets you provided, in which a view is added to the "ChartDetails" region, perhaps, it could be useful to compare the way you add the views and retrieve the regions, in order to find the cause of your problem.

You can find the sample in my SkyDrive account under the name "NestedRegionSample".

Also, I believe you could check the UI Composition QuickStart provided with Prism, in which nested regions are also used, and it also illustrate how to use both approaches to populate your regions (view discovery and view injection approach).

On the other hand, for more detailed information about the use of regions to dynamically  compose your UI see:

I hope you find this useful,

Agustin Adami
http://blogs.southworks.net/aadami