Search code examples
wpfxamlstackpanel

stackpanel xml parsed targets to go to a new row


I have a stackpanel, this stackpanel is used to populate xml parsed targets as a checkbox as shown.

    foreach (var child in stack1.Children)
    {
        if ((child is System.Windows.Controls.CheckBox) && ((System.Windows.Controls.CheckBox)child).IsChecked.Value)
        {
            masterbuildproperties.WriteLine(((System.Windows.Controls.CheckBox)child).Tag);
        }
    }

This stackpanel is embedded in a grid control. XAML:

<StackPanel Name="stack1" Grid.Row="2" Grid.Column="0" Orientation="Horizontal">
                    </StackPanel>

My question is, how do i ensure that after 7 checkboxes have been parsed, my 8th checkbox and above will go to a new row? Example as shown below:

checkbox1 checkbox2 checkbox3 checkbox4 checkbox5 checkbox6 checkbox7

checkbox8 checkbox9

Solution

  • You can use Wrap Panel to achieve this.