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?
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).