如何在 WPF 中容纳 GroupBox?
How to accommodate GroupBox in WPF?
我有一个 "GroupBox" 可以最大化 window 我转发给其他人 "GroupBox"
无法修复。任何人?
这是XAML。这是xml 不知道有没有办法添加一些定义来修复,什么标签什么的。
<UserControl x:Class="Laboratorio.Calibracion"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="490" d:DesignWidth="660">
<Grid>
<GroupBox Header="Calibracion" Margin="0,0,0,10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<GroupBox Grid.Row="0" Grid.Column="0" Header="Equipo">
<Grid>
<Label x:Name="serialLbl" Content="Serial:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/>
<TextBox x:Name="serialTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="85,10,0,0"/>
<TextBox x:Name="descripcionTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="144" Margin="209,10,0,0" IsEnabled="False"/>
<Label x:Name="resolucionLbl" Content="Resolucion:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,41,0,0"/>
<TextBox x:Name="resolucionTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="85,41,0,0"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="0" Grid.Column="1" Header="Patron">
<Grid>
<Label x:Name="patronLbl" Content="Patron:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/>
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="106,10,0,0"/>
<Label x:Name="patronLbl_Copy" Content="Niv. Referencia:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,80,0,0"/>
<TextBox x:Name="resolucionTxb_Copy" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="106,80,0,0"/>
<Label x:Name="patronLbl_Copy1" Content="Fluido:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,41,0,0"/>
<ComboBox x:Name="comboBox_Copy" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="106,41,0,0"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="1" Grid.Column="0" Header="Condificones">
<Grid>
<Label x:Name="temperaturaLbl" Content="Temperatura:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/>
<TextBox x:Name="temperaturaTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="36" Margin="94,10,0,0"/>
<Label x:Name="humedadLbl" Content="Humedad:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="135,10,0,0"/>
<TextBox x:Name="humedadTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="35" Margin="205,10,0,0"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="2" Grid.Column="0" Header="Comprobacion Inicial">
<Grid>
<DataGrid x:Name="compInicialDgv">
<DataGrid.Columns>
<DataGridTextColumn Header="Presion Patron"></DataGridTextColumn>
<DataGridTextColumn Header="Lecturas"></DataGridTextColumn>
<DataGridTextColumn Header="Error"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</GroupBox>
<GroupBox Grid.Row="2" Grid.Column="1" Header="Segunda Secuencia">
<Grid>
<DataGrid x:Name="segSecDgv">
<DataGrid.Columns>
<DataGridTextColumn Header="Presion Patron"></DataGridTextColumn>
<DataGridTextColumn Header="Lecturas"></DataGridTextColumn>
<DataGridTextColumn Header="Error"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</GroupBox>
</Grid>
</GroupBox>
</Grid>
您正在使用硬编码尺寸属性([=11=]、Width
、Height
等)。我假设您使用工具箱中的拖放功能设计了它。使用此类硬编码值调整表单大小时,您可能会得到奇怪的结果。
我建议您更改所有这些以摆脱硬编码边距,编辑父级 Grid
以使用 RowDefinitions
和 ColumnDefinitions
以及适当的大小信息(绝对值、自动, *), 设置 GroupBox
控件的 Grid.Row
Grid.Column
Grid.ColumnSpan
和 Grid.RowSpan
属性, 然后调整各种尺寸细节 (Margin
, Padding
, MinWidth
, MinHeight
, 等)根据需要。
对所有子 Grid
元素执行相同的操作。您可能还想使用其他容器元素。
这是我所说内容的精简示例。
<Grid>
<GroupBox Header="Calibracion" Margin="0,0,0,10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*" /> <!-- Or '*', 'Auto', etc -->
<ColumnDefinition Width="5*" /> <!-- Or '*', 'Auto', etc -->
</Grid.ColumnDefinitions>
<GroupBox Header="Equipo" Grid.Column="0" Grid.Row="0">
<!-- GroupBox contents here -->
</GroupBox>
<GroupBox Header="Patron" Grid.Column="1" Grid.Row="0">
<!-- GroupBox contents here -->
</GroupBox>
<GroupBox Header="Condificones" Grid.Column="0" Grid.Row="1">
<!-- GroupBox contents here -->
</GroupBox>
</Grid>
</GroupBox>
</Grid>
我有一个 "GroupBox" 可以最大化 window 我转发给其他人 "GroupBox"
无法修复。任何人?
这是XAML。这是xml 不知道有没有办法添加一些定义来修复,什么标签什么的。
<UserControl x:Class="Laboratorio.Calibracion"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="490" d:DesignWidth="660">
<Grid>
<GroupBox Header="Calibracion" Margin="0,0,0,10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<GroupBox Grid.Row="0" Grid.Column="0" Header="Equipo">
<Grid>
<Label x:Name="serialLbl" Content="Serial:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/>
<TextBox x:Name="serialTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="85,10,0,0"/>
<TextBox x:Name="descripcionTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="144" Margin="209,10,0,0" IsEnabled="False"/>
<Label x:Name="resolucionLbl" Content="Resolucion:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,41,0,0"/>
<TextBox x:Name="resolucionTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="85,41,0,0"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="0" Grid.Column="1" Header="Patron">
<Grid>
<Label x:Name="patronLbl" Content="Patron:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/>
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="106,10,0,0"/>
<Label x:Name="patronLbl_Copy" Content="Niv. Referencia:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,80,0,0"/>
<TextBox x:Name="resolucionTxb_Copy" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="106,80,0,0"/>
<Label x:Name="patronLbl_Copy1" Content="Fluido:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,41,0,0"/>
<ComboBox x:Name="comboBox_Copy" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="106,41,0,0"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="1" Grid.Column="0" Header="Condificones">
<Grid>
<Label x:Name="temperaturaLbl" Content="Temperatura:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/>
<TextBox x:Name="temperaturaTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="36" Margin="94,10,0,0"/>
<Label x:Name="humedadLbl" Content="Humedad:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="135,10,0,0"/>
<TextBox x:Name="humedadTxb" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="35" Margin="205,10,0,0"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="2" Grid.Column="0" Header="Comprobacion Inicial">
<Grid>
<DataGrid x:Name="compInicialDgv">
<DataGrid.Columns>
<DataGridTextColumn Header="Presion Patron"></DataGridTextColumn>
<DataGridTextColumn Header="Lecturas"></DataGridTextColumn>
<DataGridTextColumn Header="Error"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</GroupBox>
<GroupBox Grid.Row="2" Grid.Column="1" Header="Segunda Secuencia">
<Grid>
<DataGrid x:Name="segSecDgv">
<DataGrid.Columns>
<DataGridTextColumn Header="Presion Patron"></DataGridTextColumn>
<DataGridTextColumn Header="Lecturas"></DataGridTextColumn>
<DataGridTextColumn Header="Error"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</GroupBox>
</Grid>
</GroupBox>
</Grid>
您正在使用硬编码尺寸属性([=11=]、Width
、Height
等)。我假设您使用工具箱中的拖放功能设计了它。使用此类硬编码值调整表单大小时,您可能会得到奇怪的结果。
我建议您更改所有这些以摆脱硬编码边距,编辑父级 Grid
以使用 RowDefinitions
和 ColumnDefinitions
以及适当的大小信息(绝对值、自动, *), 设置 GroupBox
控件的 Grid.Row
Grid.Column
Grid.ColumnSpan
和 Grid.RowSpan
属性, 然后调整各种尺寸细节 (Margin
, Padding
, MinWidth
, MinHeight
, 等)根据需要。
对所有子 Grid
元素执行相同的操作。您可能还想使用其他容器元素。
这是我所说内容的精简示例。
<Grid>
<GroupBox Header="Calibracion" Margin="0,0,0,10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*" /> <!-- Or '*', 'Auto', etc -->
<ColumnDefinition Width="5*" /> <!-- Or '*', 'Auto', etc -->
</Grid.ColumnDefinitions>
<GroupBox Header="Equipo" Grid.Column="0" Grid.Row="0">
<!-- GroupBox contents here -->
</GroupBox>
<GroupBox Header="Patron" Grid.Column="1" Grid.Row="0">
<!-- GroupBox contents here -->
</GroupBox>
<GroupBox Header="Condificones" Grid.Column="0" Grid.Row="1">
<!-- GroupBox contents here -->
</GroupBox>
</Grid>
</GroupBox>
</Grid>