views:

456

answers:

1

Hello

My footer is currently composed of a label and an ItemsControl. It needs to be below 2 DataGrid controls that are similar in that they both contain a fixed width column for every day in the week and the end of it (which is what the ItemsControl in the footer has totals for).

I'm trying to solve the alignment, which seems easiest to just right align the day columns. I thought I could use a DockPanel as a container and Dock=Right on the ItemsControl like below, but everything is starting on the left after the label.

<DockPanel x:Name="columnTotals" DockPanel.Dock="Bottom" >

    <Label ... DockPanel.Dock="Left" Width="Auto">Grand Totals</Label>

        <ItemsControl DockPanel.Dock="Right"
            ItemsSource="{Binding Path=TotalTimeViewModels, Mode=OneWay}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>

    </DockPanel>

So my primary question in this post is: why doesn't the ItemsControl actually dock to the right of it's parent container (currently also a DockPanel)?

Cheers,
Berryl

The secondary and more complicated question is how to make a footer line up with DataGrid columns. My main thought to date has been to use the fact that the last columns are always the same and their width is fixed.

I can make things line up with a StackPanel using FlowDirection=RightToLeft and 8 children labels (as opposed to one ItemsControl), but this has the disadvantages of making the XAML bloated and requires the text to be RightToLeft to reverse the container flow - it's messy and confusing to look at.

I guess the footer also could be another DataGrid, but the columns wouldn't be the same so I'd still have to solve the alignment by either working right to left as I'm doing now, or figure out what the starting point of the day columns is both initially and after a resize (I do not know how to do that).

Again, thanks for reading this and Cheers,
Berryl

A: 

This code solves the alignment problem using a DockPanel:

<DockPanel LastChildFill="True" DockPanel.Dock="Bottom" >

    <ItemsControl DockPanel.Dock="Right" Width="Auto" ... />

    <Label ... Width="Auto">Grand Totals</Label>

</DockPanel>

Cheers,
Berryl

Berryl