Region defined in Style?

Topics: Prism v1, Prism v2 - Silverlight 2, Prism v2 - WPF 3.5
Jan 22, 2009 at 1:43 AM
Hi all,

I have a requirement whereby I have to divide a tabcontrol into two sections, the first section holds tabitem views and the second section displays help views.  I'm using a style which has a region defined for the Help section using a grid and grid splitter however at runtime the RegionManager does not have the Help region in the region collection.  My question is this... is it not possible to define a region in a style??

My style for the tab control looks like this:

 

 

<Style TargetType="{x:Type TabControl}">

 

 

 

<Setter Property="Template">

 

 

 

<Setter.Value>

 

 

 

<ControlTemplate TargetType="{x:Type TabControl}">

 

 

 

<Grid>

 

 

 

<Grid.RowDefinitions>

 

 

 

<RowDefinition Height="Auto"/>

 

 

 

<RowDefinition Height="*"/>

 

 

 

</Grid.RowDefinitions>

 

 

 

<TabPanel

 

 

Grid.Row="0"

 

 

Panel.ZIndex="1"

 

 

Margin="0,0,4,-1"

 

 

IsItemsHost="True"

 

 

Background="Transparent" />

 

 

 

<Border

 

 

Grid.Row="1"

 

 

BorderBrush="Black"

 

 

BorderThickness="0"

 

 

CornerRadius="12, 12, 12, 12">

 

 

 

<Grid>

 

 

 

<Grid.ColumnDefinitions>

 

 

 

<ColumnDefinition Width="*" />

 

 

 

<ColumnDefinition Width="3" />

 

 

 

<ColumnDefinition Width="147" />

 

 

 

</Grid.ColumnDefinitions>

 

 

 

<Border Margin="10,5,10,10" Grid.Row="1" Grid.Column="0" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="{DynamicResource SolidFocusBrush}" BorderThickness="2,2,2,2">

 

 

 

<ContentPresenter ContentSource="SelectedContent" />

 

 

 

</Border>

 

 

 

<GridSplitter Grid.Column="1" Grid.Row="1" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent" />

 

 

 

<Border Margin="0,5,10,10" Grid.Row="1" Grid.Column="2" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="#FFFFFF" BorderThickness="2,2,2,2">

 

 

 

<ItemsControl x:Name="HelpRegionWorkspace" cal:RegionManager.RegionName="{x:Static inf:RegionNames.HelpRegion}"/>

 

 

 

</Border>

 

 

 

</Grid>

 

 

 

</Border>

 

 

 

</Grid>

 

 

 

</ControlTemplate>

 

 

 

</Setter.Value>

 

 

 

</Setter>

 

 

 

</Style>

 

Jan 22, 2009 at 4:58 PM

Hi

 

Generally, the views are the ones that define regions and all the regions mechanism was made with that consideration. Styles are usually modified/replaced very frequently by different people (designers using Blend for example) and it is not a safe place to define a region (one minor change to the region definition in a style could impact the whole application).

 

I would suggest you to use two different controls, one TabControl to hold all your TabItem views, and a separated ItemsControl / ContentControl that defines the HelpRegion (and apply the styles to them). Once defined, you can then modify their templates.

 

Please let me know if this helps.

 

Mariano Converti

http://blogs.southworks.net/mconverti

Jan 22, 2009 at 11:26 PM

Thanks Mariano

Initially I had it set up the way you suggested however our UI design requirement was changed so the help region appears embedded in the tabcontrol as apposed to being placed next to the tabcontrol.  The only way I could think to do this without creating a custom tabcontrol was to do it via template/style.  Do you have any suggestions as to how I could achieve this using some other approach?