Search code examples
wpfprismregiongridsplitter

Resizing WPF Prism Regions


In a WPF Prism app, I have two separate views in two separate regions, say LeftRegion and RightRegion. I would like to be able to drag the edge of LeftRegion (ie. the view in LeftRegion) like a gridsplitter works. Any ideas on how to accomplish this? Thank you.

EDIT: Here is the ShellView.xaml called by bootstrapper.cs that defines the regions.

<Grid >
 <Grid.RowDefinitions>
 <RowDefinition Height ="*"/>
 </Grid.RowDefinitions>
 <Grid.ColumnDefinitions>
 <ColumnDefinition Width="215"/>
  <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ContentControl  Grid.Column ="0" Height ="500" prism:RegionManager.RegionName="LeftRegion" />
<GridSplitter Grid.Column ="0" Width="5" HorizontalAlignment="Right" VerticalAlignment="Stretch" ResizeBehavior="CurrentAndNext"/>
<ContentControl Grid.Column="1" Height ="400" prism:RegionManager.RegionName="RightRegion" />
</Grid>

Solution

  • Since Prism regions are nothing but UIElements, typically ContentPresenters, you should be able to use a GridSplitter as usual:

    <Window x:Class="WpfApp1.MainWindow"
            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:local="clr-namespace:WpfApp2"
            prism:RegionManager.RegionName="LeftRegion"
            mc:Ignorable="d"
            Title="MainWindow" Height="300" Width="300">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
    
            <ContentControl prism:RegionManager.RegionName="LeftRegion" />
    
            <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" />
    
            <ContentControl Grid.Column="2" prism:RegionManager.RegionName="RightRegion" />
        </Grid>
    </Window>