I want the red button in the expander header to be docked right. How can I do this?

<StackPanel Orientation="Vertical" x:Name="spTest" Margin="10">
<Border BorderBrush="Black" BorderThickness="1">
<Expander Margin="5,0,5,0">
<Expander.Header>
<Grid Margin="5,0,0,0" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBlock Text="TEXT1 1231521312" Grid.Column="0" FontSize="18" Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<TextBlock Grid.Column="1" FontSize="18" FontStyle="Italic" Margin="10,0,10,0" Foreground="Black" VerticalAlignment="Center" Text="Text2"/>
<Button x:Name="btnRemove" Grid.Column="2" Width="40" Height="40" Background="#F8CECC" Content="X" FontWeight="Normal" FontSize="18" BorderBrush="#B95753"/>
</Grid>
</Expander.Header>
</Expander>
</Border>
</StackPanel>
Thank you!!
The issue comes from
ContentPresenterused for header in default template.ContentPresenterhas it'sHorizontalAlignmentset not to theStretch. To change it you could try to bindHorizontalAlignmentof theGridto theHorizontalAlignmentof theContentPresenter.Another way, which would work with nested
Expanderis to set/bind theGrid.Width.Another way would be override default template for
Expandersee Expander Styles and Templates.