WPF用户控件不随主窗口调整控件、窗口、用户、WPF

2023-09-05 02:17:50 作者:坐在坟地看星星

我试图让一个WPF用户控件包含两个组框和两个的ListView S在各组中。这里是XAML code用户控件:

I'm trying to make a WPF user control that includes two group boxes and two ListViews in each group box. Here is the XAML code for the user control:


    <UserControl x:Class="TestGroupControl.TestGroupControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="500" Width="700" MinWidth="300" MinHeight="200">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="225*" />
                <RowDefinition Height="225*" />
            </Grid.RowDefinitions>
            <GroupBox Grid.Row="0" Header="Test Data" Margin="2,2,2,2" Name="testDataGroupBox">
                <Grid>
                    <ListView Margin="2,2,2,2" Name="testDataListView" ></ListView>
                </Grid>
            </GroupBox>
            <GroupBox Grid.Row="1" Header="Test Parameters" Margin="2,2,2,2" Name="testParametersGroupBox">
                <Grid>
                    <ListView Margin="2,2,2,2" Name="testParametersListView" ></ListView>
                </Grid>
            </GroupBox>
        </Grid>
    </UserControl>

我现在面临的问题是,当我尝试调整主窗口中保存用户控件,用户控件将不会跟随父窗口,并调整为好。

The problem I am facing is that when I try to resize the main window holding the user control, the user control won't follow the parent window and resize as well.

任何的想法是AP preciated。谢谢你。

Any thoughts are appreciated. Thank you.

推荐答案

你指定的身高宽度属性,在该用户的固定值。删除这些属性,然后设置的Horizo​​ntalAlignment VerticalAlignment 在主窗口中的控制实例的弹力。这应该照顾它。

You're specifying the Height and Width properties as fixed values in the UserControl. Remove those properties, and set the HorizontalAlignment and VerticalAlignment properties of the control instance in the main window to Stretch. That should take care of it.