Grid expander header - can't get arrangement right

c#, wpf

Solution

I had the same problem and if I remember it right the problem is that the `ContentPresenter` for `Expander.Header` doesn't care the `HorizontalAlignment` of `Expander`. I found somewhere this nice workaround:

<Expander.Header>
    <Grid HorizontalAlignment="{Binding Path=HorizontalAlignment, RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}}, Mode=OneWayToSource}">
        ...
    </Grid>
</Expander.Header>

Problem

I have the following `Expander` defined for a `DataGrid`. ``` <Expander IsExpanded="True" HorizontalAlignment="Stretch" Background="Blue"> <Expander.Header> <Grid HorizontalAlignment="Stretch" Background="BurlyWood"> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBlock Text="{Binding Path=Name, StringFormat=\{0:D\}}" FontWeight="Bold" /> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="1"> <TextBlock Text="Total : "/> <TextBlock Text="{Binding Path=Items, Converter={StaticResource sumConverter}}" FontWeight="Bold"/> </StackPanel> </Grid> </Expander.Header> <ItemsPresenter /> </Expander> ``` I need to display the item name in the left and the sum in the right end of the group header. However what I get is this: How can I move the 'Total' to the right end of the header?

Original source