--- title: "How to: Choose Between StackPanel and DockPanel" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "controls [WPF], DockPanel" - "DockPanel control [WPF], StackPanel control compared to" - "StackPanel control [WPF], DockPanel control compared to" - "controls [WPF], StackPanel" ms.assetid: f9239086-451f-42e6-81f7-ef89ef349742 --- # How to: Choose Between StackPanel and DockPanel This example shows how to choose between using a or a when you stack content in a . ## Example Although you can use either or to stack child elements, the two controls do not always produce the same results. For example, the order that you place child elements can affect the size of child elements in a but not in a . This different behavior occurs because measures in the direction of stacking at [Double.PositiveInfinity](xref:System.Double.PositiveInfinity); however, measures only the available size. The following example demonstrates this key difference between and . [!code-cpp[StackPanelOvw4#1](~/samples/snippets/cpp/VS_Snippets_Wpf/StackPanelOvw4/CPP/StackPanel_Ovw_Sample4.cpp#1)] [!code-csharp[StackPanelOvw4#1](~/samples/snippets/csharp/VS_Snippets_Wpf/StackPanelOvw4/CSharp/StackPanel_Ovw_Sample4.cs#1)] [!code-vb[StackPanelOvw4#1](~/samples/snippets/visualbasic/VS_Snippets_Wpf/StackPanelOvw4/VisualBasic/StackPanelSamp.vb#1)] [!code-xaml[StackPanelOvw4#1](~/samples/snippets/xaml/VS_Snippets_Wpf/StackPanelOvw4/XAML/default.xaml#1)] ## See also - - - [Panels Overview](panels-overview.md)