考考你一个WPF布局

要创建如图一样布局,请问怎么实现?其实考题本身没有任何实用价值,只是一种思维的拓展。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

看似用DockPanel实现,那么就错了,因为Top Button没有占据Top的全部。
实际上是用了很简单Grid实现,如果你能用其他方式实现,欢迎跟帖。
 

Code:
  1. <Window x:Class="GridDemo.ComplexGridWindow"  
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  4.         Title="ComplexGridWindow" Height="300" Width="300">  
  5.     <Grid>  
  6.         <Grid.RowDefinitions>  
  7.             <RowDefinition Height="50" />  
  8.             <RowDefinition />  
  9.             <RowDefinition Height="50" />  
  10.         </Grid.RowDefinitions>  
  11.         <Grid.ColumnDefinitions>  
  12.             <ColumnDefinition Width="50" />  
  13.             <ColumnDefinition />  
  14.             <ColumnDefinition Width="50" />  
  15.         </Grid.ColumnDefinitions>  
  16.            
  17.         <Button Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Content="Top" />  
  18.         <Button Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Content="Right" />  
  19.         <Button Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Content="Bottom" />  
  20.         <Button Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Content="Left" />  
  21.         <Button Grid.Row="1" Grid.Column="1" Content="Fill" />  
  22.     </Grid>  
  23. </Window>  

最后我想说的就是:学习不会一味的Follow code in book,而是要Thinking。



 

你可能感兴趣的:(Class,button,WPF)