I'm trying to make a WPF user control that includes two group boxes and two ListView
s 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.
A window is managed by the OS and is placed on the desktop. A UserControl is managed by wpf and is placed in a Window or in another UserControl. Applcations could be created by have a single Window and displaying lots of UserControls in that Window.
A customControl can be styled and templated and best suited for a situation when you are building a Control Library. On the contrary, a UserControl gives you an easy way to define reusable chunk of XAML which can be reused widely in your application and when you don't need to use it as a Control Library .
The Viewbox control is used to stretch or scale a child element.
User controls, in WPF represented by the UserControl class, is the concept of grouping markup and code into a reusable container, so that the same interface, with the same functionality, can be used in several different places and even across several applications.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With