WPF user control does not resize with main window
Asked Answered
A

2

9

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.

Any thoughts are appreciated. Thank you.

Apian answered 4/6, 2010 at 17:27 Comment(0)
B
24

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.

Bertberta answered 4/6, 2010 at 17:34 Comment(0)
P
0

İf You Use a ViewBox and a Canvas on your user control will fix all the mainwindow sizes

<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">

  <canvas>

--- all your controls -- 

     </Canvas>
        </Viewbox>
Polysepalous answered 15/5, 2019 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.