WrapPanel::Orientation Property
Gets or sets a value that specifies the dimension in which child content is arranged.
Assembly: PresentationFramework (in PresentationFramework.dll)
public: property Orientation Orientation { Orientation get(); void set(Orientation value); }
Property Value
Type: System.Windows.Controls::OrientationAn Orientation value that represents the physical orientation of content within the WrapPanel as horizontal or vertical. The default value is Horizontal.
If the Orientation property is set to Horizontal, child content forms horizontal rows first and if necessary forms vertical stacks of rows. If the Orientation property is set to Vertical, child content is first positioned in a vertical column, and if there is not enough space, wrapping occurs and additional columns in the horizontal dimension are added.
Identifier field | |
Metadata properties set to true |
The following example demonstrates how to set the Orientation property in Extensible Application Markup Language (XAML).
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="WrapPanel Properties Sample"> <Border HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="2"> <WrapPanel Orientation="Horizontal" Background="Azure" ItemWidth="25" ItemHeight="25" Height="200" Width="200"> <Button Width="200">Button 1</Button> <Button>Button 2</Button> <Button>Button 3</Button> </WrapPanel> </Border> </Page>
The following example demonstrates how to set the Orientation property by using code.
// Create the application's main window mainWindow = gcnew System::Windows::Window(); mainWindow->Title = "WrapPanel Sample"; // Instantiate a new WrapPanel and set properties myWrapPanel = gcnew WrapPanel(); myWrapPanel->Background = Brushes::Azure; myWrapPanel->Orientation = Orientation::Horizontal; myWrapPanel->ItemHeight = 25; myWrapPanel->ItemWidth = 75; myWrapPanel->Width = 150; myWrapPanel->HorizontalAlignment = HorizontalAlignment::Left; myWrapPanel->VerticalAlignment = VerticalAlignment::Top; // Define 3 button elements. Each button is sized at width of 75, so the third button wraps to the next line. btn1 = gcnew Button(); btn1->Content = "Button 1"; btn2 = gcnew Button(); btn2->Content = "Button 2"; btn3 = gcnew Button(); btn3->Content = "Button 3"; // Add the buttons to the parent WrapPanel using the Children.Add method. myWrapPanel->Children->Add(btn1); myWrapPanel->Children->Add(btn2); myWrapPanel->Children->Add(btn3); // Add the WrapPanel to the MainWindow as Content mainWindow->Content = myWrapPanel; mainWindow->Show();
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="WrapPanel Sample"> <Border HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="2"> <WrapPanel Background="LightBlue" Width="200" Height="100"> <Button Width="200">Button 1</Button> <Button>Button 2</Button> <Button>Button 3</Button> <Button>Button 4</Button> </WrapPanel> </Border> </Page>
Available since 3.0