在运行时重新安排WrapPanel中的控件

Abd*_*aid 5 c# wpf xaml wrappanel button

我有一个WPF WrapPanel,它包含一些Buttons,我想在运行时重新安排它们.设计时的XAML代码如:

<Grid x:Name="LayoutRoot">
    <WrapPanel Margin="133,127,216,189" Background="#FF979797">
        <Button Content="Button" Width="75"/>
        <Button Content="Button" Width="75"/>
        <Button Content="Button" Width="75"/>
        <Button Content="Button" Width="75"/>
        <Button Content="Button" Width="75"/>
        <Button Content="Button" Width="75"/>
    </WrapPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

但是,我想Buttons在运行时重新安排.你能帮帮我吗?

Chr*_*son 0

如果要在运行时重新排列子项,您有两个选择:在代码而不是 XAML 中创建(或至少操作)WrapPannel 的子项,或者设置触发器(在 Style 标记中)以根据需要操作按钮。

这是一个例子。