WindowRegionAdapter

Nov 27, 2008 at 2:21 PM
Hello,
how can I resize the Control in the Window when the Window itself is resized by the user?

Any ideas?
Dec 30, 2008 at 8:36 PM
Set the Height and Width of the UserControl to Auto and set the starting or lastsaved size of the usercontrol in the Loaded event of the UserControl.
Dec 31, 2008 at 1:49 PM
For anyone else having problems with this here is my final solution.

Create an interface for you usercontrols like the following adding any other properties etc all your usercontrols should Implement, ie. I also have a windows closing methed so I can tell at the usercontrol level if the appliction is closing to give the user a chance to save any unsaved changed or cancel the close event leaving the app open.

    public interface IWindow {
        String Title { get; set; }
        double WinHeight { get; set; }
        double WinWidth { get; set; }
    }

All your modules usercontrols should implement this interface obviously.  In the modules view contructor set the WinHeight and WinWidth to the starting values of the window size you want.  Also setup a method to update these sizes via the SizeChanged event if you want to keep track of the window size to say save it to user preferences and restart with the previous window size.  Note I also set the window minsize based on the usercontrol minsize which defaults to 0,0 if you don't want to set a minimum size.

Update the Style you base your WindowRegionAdapter on to include the following

    <Style x:Key="ModuleWindowTemplate" TargetType="{x:Type Window}">
        <Setter Property="MinWidth" Value="{Binding Path=Content.MinWidth, RelativeSource={RelativeSource Self}}" />
        <Setter Property="MinHeight" Value="{Binding Path=Content.MinHeight, RelativeSource={RelativeSource Self}}" />
        <Setter Property="Width" Value="{Binding Path=Content.WinWidth, RelativeSource={RelativeSource Self}}" />
        <Setter Property="Height" Value="{Binding Path=Content.WinHeight, RelativeSource={RelativeSource Self}}" />
        <Setter Property="Title" Value="{Binding Path=Content.Title, RelativeSource={RelativeSource Self}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Grid Width="Auto" Height="Auto" >
                        <ContentPresenter />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Of course there may be a better way to do this but this is what I've come up with that works for me.