Search code examples
wpfgroupbox

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


Solution

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