在WPF Prism MVVM中,如何从子视图调整父视图的大小

问题描述 投票:0回答:1

在使用Prism的MVVM应用程序中,子视图和viewmodel被加载到父视图UserControl“ ContentRegion”中

并且父视图具有固定大小

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

如何从子视图模型调整父视图大小

<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>```


c# wpf prism
1个回答
0
投票

我不建议尝试从视图调整父窗口的大小,因为它不知道其位置。

尝试与SizeToContent一起玩。

如果确实需要手动调整大小,则可以使用Prism的IEventAggregator,并使用PubSubEvent<T>进行Publish()和Subscribe()事件。在View的上下文中,您需要Publish()事件。然后在Window上订阅该事件并处理大小参数。

伪代码:

public class ResizeParentWindowEvent : PubSubEvent<YourSizeInfo> { }

eventAggregator.GetEvent<ResizeParentWindowEvent>().Publish(your_size_info_object);
© www.soinside.com 2019 - 2024. All rights reserved.