WPF教程四;布局之DockPanel面板

來源:互聯網
上載者:User

標籤:pre   中控   startup   ati   location   com   color   對象   技術分享   

DockPanel:固定面板

      DockPanel定義一個地區,在此地區中,您可以使子項目通過描點的形式排列,這些對象位於 Children 屬性中。固定面板類似於WinForm中控制項的Dock屬性。DockPanel會對每個子項目進行排序,並將根據指定的邊進行停靠,多個停靠在同側的元素則按順序排序。在DockPanel中,指定停靠邊的控制項,會根據定義的順序佔領邊角,所有控制項絕不會交疊。

     預設情況下,後添加的元素只能使用剩餘空間,無論對DockPanel的最後一個子項目設定任何停靠值,該子項目都將始終填滿剩餘的空間。如果不希望最後一個元素填充剩餘地區,可以將DockPanel屬性LastChildFill設定為false,還必須為最後一個子項目顯式指定停靠方向。

1、填充整個剩餘空間

使用XAML代碼實現:

 1 <Window x:Class="WpfDemo.MainWindow" 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4         Title="DockPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen"> 5     <DockPanel> 6         <Button DockPanel.Dock="Left" Content="ButtonLeft"></Button> 7         <Button DockPanel.Dock="Top" Content="ButtonTop"></Button> 8         <Button DockPanel.Dock="Right" Content="ButtonRight"></Button> 9         <Button DockPanel.Dock="Bottom" Content="ButtonBottom"></Button>10         <Button  Content="ButtonTop"></Button>11     </DockPanel>12 </Window>

2、最後元素不填充剩餘空間

使用XAML代碼實現:

 1 <Window x:Class="WpfDemo.MainWindow" 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4         Title="DockPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen"> 5     <DockPanel LastChildFill="False"> 6         <Button DockPanel.Dock="Left" Content="ButtonLeft"></Button> 7         <Button DockPanel.Dock="Top" Content="ButtonTop"></Button> 8         <Button DockPanel.Dock="Right" Content="ButtonRight"></Button> 9         <Button DockPanel.Dock="Bottom" Content="ButtonBottom"></Button>10         <Button  DockPanel.Dock="Top" Content="最後一個Button不填充剩餘空間"></Button>11     </DockPanel>12 </Window>

 

WPF教程四;布局之DockPanel面板

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.