How to bind a group package to the left, but allow the group box to expand to the maximum width when stretched

I recently tried to help my friend with the problem of hosting in WPF, and I can’t figure out how to make it work, and it seems like such a simple thing, so I thought that I would take advantage of the wealth of knowledge here :) That he wants it for groupbox1 to authorize the maxwidth value and then stay tied to the left while the space to the right of the group window grows. Therefore, to keep it simple, I'm just going to post some example code for the situation now :) If someone has some light to get rid of the situation, answer. Thanks everyone!

<Window x:Class="GroupBoxTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="147" Width="525">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="151*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="148" />
        <ColumnDefinition Width="355*" />
    </Grid.ColumnDefinitions>
    <GroupBox Header="groupBox1" Margin="14,12,41,8" Name="groupBox1" MaxWidth="450" Grid.Column="1">
        <Grid />
    </GroupBox>
    <GroupBox Header="groupBox2" Margin="12,12,13,8" Name="groupBox2">
        <Grid />
    </GroupBox>
</Grid>

+5
source share
3

MaxWidth = "450" ​​ ColumnDefinition GroupBox.

<Grid>
    <Grid.RowDefinitions>
       <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
       <ColumnDefinition Width="148" />
       <ColumnDefinition Width="*" MaxWidth="450" />
    </Grid.ColumnDefinitions>
    <GroupBox 
        Name="groupBox1" 
        Header="groupBox1"
        Margin="14,12,41,8"
        Grid.Column="1">
    </GroupBox>
    <GroupBox Header="groupBox2" Margin="12,12,13,8" Name="groupBox2">
    </GroupBox>
</Grid>
+1

MaxWidth="450" ColumnDefinition GroupBox.

<ColumnDefinition Width="355*" MaxWidth="450"/>

1 450, HorizontalAlignment="Left" GroupBox Width .

ActualWidth a ColumnDefinition ,

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="151*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="148" />
        <ColumnDefinition Width="355*" />
    </Grid.ColumnDefinitions>
    <Rectangle Name="sizeElement" Fill="Transparent" Margin="14,12,41,8" Grid.Column="1"/>
    <GroupBox Header="groupBox1" Margin="14,12,41,8" Name="groupBox1" MaxWidth="450" Grid.Column="1"
              HorizontalAlignment="Left"
              Width="{Binding ElementName=sizeElement, Path=ActualWidth}">
        <Grid />
    </GroupBox>
    <GroupBox Header="groupBox2" Margin="12,12,13,8" Name="groupBox2">
        <Grid />
    </GroupBox>
</Grid>
+2

, :

<GroupBox Header="groupBox1" Margin="14,12,41,8" Name="groupBox1" MaxWidth="450" Grid.Column="1">
    <GroupBox.Style>
        <Style TargetType="GroupBox">
             <Style.Triggers>
                <Trigger Property="ActualWidth" Value="450">
                        <Setter Property="Width" Value="450"/>
                        <Setter Property="HorizontalAlignment" Value="Left"/>   
                    </Trigger>       
                 </Style.Triggers>
            </Style>    
        </GroupBox.Style>
    <Grid />
</GroupBox>
0

All Articles