WPF布局按钮切换,效果和代码如下
<Window x:Class="LayoutTransitionsDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:LayoutTransitionsDemo"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Loaded="OnLoad">
<Grid Background="{StaticResource BgKey}">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0" Name="ButtonGrid">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Row="0" Grid.Column="0" Click="OnGrid5"
AutomationProperties.HelpText="Move all buttons into the five by five (5x5) grid">
MoveToGrid5
</Button>
<Button Grid.Row="1" Grid.Column="0" Click="OnGrid3"
AutomationProperties.HelpText="Move all buttons into the three by three (3x3) grid">
MoveToGrid3
</Button>
<Button Grid.Row="2" Grid.Column="0" Click="OnAdvanceClick"
AutomationProperties.HelpText="Increase the starting location in the grid by one">
Grid:Advance
</Button>
<Button Grid.Row="3" Grid.Column="0" Click="OnRetreatClick"
AutomationProperties.HelpText="Decrease the starting location in the grid by one">
Grid:Retreat
</Button>
<Button Grid.Row="4" Grid.Column="0" Click="OnStackPanel"
AutomationProperties.HelpText="Move all buttons into the stack panel">
MoveToStack
</Button>
<Button Grid.Row="5" Grid.Column="0" Click="OnStackVertical"
AutomationProperties.HelpText="Set the Stackpanel's orientation to vertical">
Stack:Vertical
</Button>
<Button Grid.Row="6" Grid.Column="0" Click="OnStackHorizontal"
AutomationProperties.HelpText="Set the Stackpanel's orientation to horizontal">
Stack:Horizontal
</Button>
<Button Grid.Row="7" Grid.Column="0" Click="OnWrapPanel"
AutomationProperties.HelpText="Move all buttons into the wrap panel">
MoveToWrap
</Button>
<Button Grid.Row="8" Grid.Column="0" Click="OnWrapVertical"
AutomationProperties.HelpText="Set the wrappanel's orientation to vertical">
Wrap:Vertical
</Button>
<Button Grid.Row="9" Grid.Column="0" Click="OnWrapHorizontal"
AutomationProperties.HelpText="Set the wrappanel's orientation to horizontal">
Wrap:Horizontal
</Button>
</Grid>
<Grid Grid.Row="0" Grid.Column="1" Name="LTLGrid">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
<Grid Grid.Row="0" Grid.Column="1" Name="LTLGrid2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
<StackPanel Grid.Row="0" Grid.Column="1" Name="LTLStackPanel" />
<WrapPanel Grid.Row="0" Grid.Column="1" Margin="100" Name="LTLWrapPanel" />
<Canvas Grid.Row="0" Grid.Column="1" Name="LTLCanvas" />
</Grid>
</Window>