user302775
user302775

Reputation: 45

WPF GroupBox Custom Header Alignment Left And Right

I am trying to add content to a groupbox header, so that part of the content aligns to the left and the other part aligns to the right.

I've tried adding a grid as the content to the header with 2 columns, but everything aligns left. I want column 1 to align left, and column 2 to align on the right side of the group box.

Is this even possible?

Thanks

Upvotes: 3

Views: 3721

Answers (2)

Ashley Grenon
Ashley Grenon

Reputation: 9565

I tried a this and if I understand your problem correctly I got it working. I just used textblocks:

<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>

Upvotes: 0

HCL
HCL

Reputation: 36775

The problem here is, which size the tab-header should use. You can define your header as described and set minumum width for your Grid. This would probably have the effect you're 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>

More influence for the optical style of GroupBox you can get through the HeaderTemplate and the Template-property.

Upvotes: 1

Related Questions