Sp1.HorizontalAlignment = ĮlseIf (li.Content.ToString() = "Center") Then Sp1.HorizontalAlignment = ĮlseIf (li.Content.ToString() = "Right") Then Private Sub changeHorAlign(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)
Sp1.Orientation = .HorizontalĮlseIf li.Content.ToString() = "Vertical" Then If (li.Content.ToString() = "Horizontal") Then Private Sub changeOrientation(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)ĭim li As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem) Sp1.VerticalAlignment = Įlse if (li.Content.ToString() = "Bottom") Private void changeVertAlign(object sender, SelectionChangedEventArgs args) Sp1.HorizontalAlignment = Įlse if (li.Content.ToString() = "Stretch") Sp1.HorizontalAlignment = Įlse if (li.Content.ToString() = "Center") Sp1.HorizontalAlignment = Įlse if (li.Content.ToString() = "Right") Private void changeHorAlign(object sender, SelectionChangedEventArgs args) Sp1.Orientation = .Horizontal Įlse if (li.Content.ToString() = "Vertical") If (li.Content.ToString() = "Horizontal") ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem) private void changeOrientation(object sender, SelectionChangedEventArgs args) StackPanel is identified by the Name sp1.
The following code-behind file defines the changes to the events that are associated with the ListBox selection changes. When a user selects a value in any of the ListBox elements, the associated property of the StackPanel and its child Button elements change. Each ListBox represents the possible values of the Orientation, HorizontalAlignment, and VerticalAlignment properties of a StackPanel. The following example creates three ListBox elements in Extensible Application Markup Language (XAML).
This example shows how to adjust the Orientation of content within a StackPanel element, and also how to adjust the HorizontalAlignment and VerticalAlignment of child content.