WPF GroupBox Custom Header Alignment Left and Right

I am trying to add content to the group header so that part of the content is aligned to the left and the other part is aligned to the right.

I tried adding a grid as content to a two-column header, but everything aligns to the left. I want column 1 to align to the left and column 2 to the right of the group field.

Is it possible?

thank

+3
source share
2 answers

The problem is what size the tab title should use. You can define your title as described and set a minimum width for your grid. This will likely have the effect you are looking for.

<Grid MinWidth="250">
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="Auto"/>
  </Grid.ColumnDefinitions>

  <TextBlock Text="Test on the left"/>

  <TextBlock Grid.Column="1" Text="Right" HorizontalAligment="Right" />

</Grid>

GroupBox HeaderTemplate -property.

+1

, , . :

<GroupBox>
    <GroupBox.Header>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefintion />
                <ColumnDefintion />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" Text="Blah1" />
            <TextBlock Grid.Column="1" Text="Blah2" HorizontalAlignment="Right" />
        </Grid>
    </GroupBox.Header>
</GroupBox>
+1

Source: https://habr.com/ru/post/1793706/


All Articles