0
votes

In MVVM application using Prism, a child view and viewmodel is loaded in parent view UserControl "ContentRegion"

and parent view has fixed size

    Height="868"
    Width="1024"
    MinHeight="868" 
    MinWidth="1024"

How to resize parent view size from child viewmodel

<Window 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:prism="http://prismlibrary.com/"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        prism:ViewModelLocator.AutoWireViewModel="True"
        Height="868"
        Width="1024"
        MinHeight="868" 
        MinWidth="1024">
    <Grid>
        <UserControl prism:RegionManager.RegionName="ContentRegion" />
    </Grid>
</Window>```


1
This is neither MVVM- nor Prism-related, this is about wpf controls doing view-stuff. I would not want to force a view model into this. - Haukinger

1 Answers

0
votes

I would not recommend trying to resize the parent window from a view as it does not know where it is located.

Try to play with SizeToContent.

If your really need to resize it manually, you can use Prism's IEventAggregator using PubSubEvent<T> to Publish() und Subscribe() events. From within the View's context you'll want to Publish() the event. And on the Window you Subscribe() to that event and handle the sizing parameters.

Pseudo code:

public class ResizeParentWindowEvent : PubSubEvent<YourSizeInfo> { }

eventAggregator.GetEvent<ResizeParentWindowEvent>().Publish(your_size_info_object);