tags:

views:

163

answers:

2

I've got the following markup in a WPF UserControl:

<Border Name="_border" BorderThickness="4" BorderBrush="Blue">
    <Canvas Name="_canvas" Background="Black" >
        <DockPanel LastChildFill="True">
            <ItemsControl Name="_itemsControl" Background="Bisque" AllowDrop="True" Height="100" Width="100"
                      HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      ItemTemplate="{StaticResource pictureTemplate}"
                      ItemsPanel="{StaticResource panelTemplate}"
                      Drop="_itemsControl_Drop" 
                      DragOver="_itemsControl_DragOver" 
                      DragLeave="_itemsControl_DragLeave" 
                      PreviewMouseLeftButtonDown="_itemsControl_PreviewMouseLeftButtonDown"
                      PreviewMouseMove="_itemsControl_PreviewMouseMove">

        </ItemsControl>
             </DockPanel>
    </Canvas>
</Border>

I would like the ItemsControl to fill all of the available space, but it is not obeying the DockPanel's LastChildFill property. The Horizontal and Vertical "Stretch" values aren't helping either. What am I missing?

+2  A: 

Whats the size of your DockPanel? Try setting a background on your DockPanel for testing.

I don't think that you problem is with your ItemsControl not stretching to fill your DockPanel, but actually your DockPanel is not stretching to fit inside the Canvas Control. Canvas control and its children will not resize to fit thier parent.

bendewey
+2  A: 

If you remove the Canvas completely, you will not have this problem. Once you introduce a canvas, you need to set size and position of elements in the Canvas (like the DockPanel).

foson