WPF笔记(2.2 DockPanel)——Layout

读完了这一节,发现DockPanel就是过去winform中的Dock属性。原来的Dock属性是子控件设置,而其父亲级别不用设置。现在WPF改为在父亲级别抽象出一个DockPanel,然后设置其下子控件的Dock属性。
<DockPanel LastChildFill="True">
    
<Button DockPanel.Dock="Left">Left</Button>
    
<Button DockPanel.Dock="Right">Right</Button>
    
<Button DockPanel.Dock="Top">Top</Button>
    
<Button DockPanel.Dock="Bottom">Bottom</Button>
    
<Button>Fill</Button>
</DockPanel>
DockPanel有一个LastChildFill属性,一般设置为true,给最后一个元素使用,所以最后一个元素不用设置Dock属性,自动占有剩余所有空间。我试过,LastChildFill属性不设置,默认也是true;设置为false,则xaml报错。

最后一句话,在Form级别一般用DockPanel对其上的子模块进行布局。比较粗,考虑的是全局观问题。比如说ToolBar,StatusBar,Navigation等等。
posted @ 2007-03-31 13:28  包建强  Views(1540)  Comments(2Edit  收藏  举报