title: WPF GroupBox Header location in center
body: <p>I have edited the standard GroupBox template as I wanted to customize it. Apart from other customizations, I wanted the GroupBox header to be Horizontally aligned in the Center instead of Left or Right. The alignment of the Header is not a problem however, the real problem is the OpacityMask defined for the Border controls. The opacity mask sets the transparent space behind the group box header where the borders are not drawn. I haven't able to figure it out how to place the transparent space gap behind the group box header when I set the header to the center.</p>
  
  <pre><code>&lt;ControlTemplate x:Key="GroupBoxControlTemplate1" TargetType="{x:Type GroupBox}"&gt;
      &lt;Grid SnapsToDevicePixels="True"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="6"/&gt;
              &lt;ColumnDefinition Width="Auto"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="6"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="6"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Border Background="{TemplateBinding Background}" BorderBrush="Transparent" 
                  BorderThickness="{TemplateBinding BorderThickness}" 
                  CornerRadius="4" Grid.Column="1" Grid.ColumnSpan="4" 
                  Grid.Row="1" Grid.RowSpan="3" HorizontalAlignment="Stretch"/&gt;
          &lt;Border x:Name="Header" Grid.Column="2" Grid.RowSpan="2" HorizontalAlignment="Left" 
                  Padding="3,1,3,0" VerticalAlignment="Stretch"&gt;
              &lt;Border.Effect&gt;
                  &lt;DropShadowEffect BlurRadius="10" Direction="334"/&gt;
              &lt;/Border.Effect&gt;
              &lt;ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                Content="{TemplateBinding Header}" 
                                ContentSource="Header" 
                                ContentStringFormat="{TemplateBinding HeaderStringFormat}" 
                                ContentTemplate="{TemplateBinding HeaderTemplate}" 
                                RecognizesAccessKey="True" Height="Auto" 
                                VerticalAlignment="Center"
                                HorizontalAlignment="Center"
                                OpacityMask="#FF3844BD" Margin="0,1,0,0"&gt;
              &lt;/ContentPresenter&gt;
          &lt;/Border&gt;
          &lt;ContentPresenter Margin="{TemplateBinding Padding}" 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                            Content="{TemplateBinding Content}" 
                            ContentStringFormat="{TemplateBinding ContentStringFormat}" 
                            ContentTemplate="{TemplateBinding ContentTemplate}" 
                            Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2"/&gt;
          &lt;Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" 
                  CornerRadius="4" Grid.ColumnSpan="3" Grid.Row="1" Grid.RowSpan="3" RenderTransformOrigin="0.5,0.5" Margin="0"&gt;
              &lt;Border.OpacityMask&gt;
                  &lt;MultiBinding ConverterParameter="7" UpdateSourceTrigger="Default"&gt;
                      &lt;MultiBinding.Converter&gt;
                          &lt;BorderGapMaskConverter/&gt;
                      &lt;/MultiBinding.Converter&gt;
                      &lt;Binding Path="ActualWidth" ElementName="Header"/&gt;
                      &lt;Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/&gt;
                      &lt;Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/&gt;
                  &lt;/MultiBinding&gt;
              &lt;/Border.OpacityMask&gt;
              &lt;Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4"&gt;
                  &lt;Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4"/&gt;
              &lt;/Border&gt;
          &lt;/Border&gt;
      &lt;/Grid&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>The header text should be at the center of the GroupBox currently it is on the left side which is the default position of GroupBox.</p>