考考你一个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。



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值