WPF使用DockPanel??棵姘宀季?/h1>
更新時間:2022年02月25日 10:39:33 作者:.NET開發(fā)菜鳥
這篇文章介紹了WPF使用DockPanel??棵姘宀季值姆椒?,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
DockPanel:??棵姘?/h2>
DockPanel定義一個區(qū)域,在此區(qū)域中,您可以使子元素通過描點(diǎn)的形式排列,這些對象位于 Children 屬性中。??棵姘孱愃朴赪inForm中控件的Dock屬性。DockPanel會對每個子元素進(jìn)行排序,并將根據(jù)指定的邊進(jìn)行??浚鄠€??吭谕瑐?cè)的元素則按順序排序。在DockPanel中,指定停靠邊的控件,會根據(jù)定義的順序占領(lǐng)邊角,所有控件絕不會交疊。
默認(rèn)情況下,后添加的元素只能使用剩余空間,無論對DockPanel的最后一個子元素設(shè)置任何停靠值,該子元素都將始終填滿剩余的空間。如果不希望最后一個元素填充剩余區(qū)域,可以將DockPanel屬性LastChildFill設(shè)置為false,還必須為最后一個子元素顯式指定??糠较?。
1、填充整個剩余空間

使用XAML代碼實(shí)現(xiàn):
<Window x:Class="WpfDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DockPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen">
<DockPanel>
<Button DockPanel.Dock="Left" Content="ButtonLeft"></Button>
<Button DockPanel.Dock="Top" Content="ButtonTop"></Button>
<Button DockPanel.Dock="Right" Content="ButtonRight"></Button>
<Button DockPanel.Dock="Bottom" Content="ButtonBottom"></Button>
<Button Content="ButtonTop"></Button>
</DockPanel>
</Window>
2、最后元素不填充剩余空間

使用XAML代碼實(shí)現(xiàn):
<Window x:Class="WpfDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DockPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen">
<DockPanel LastChildFill="False">
<Button DockPanel.Dock="Left" Content="ButtonLeft"></Button>
<Button DockPanel.Dock="Top" Content="ButtonTop"></Button>
<Button DockPanel.Dock="Right" Content="ButtonRight"></Button>
<Button DockPanel.Dock="Bottom" Content="ButtonBottom"></Button>
<Button DockPanel.Dock="Top" Content="最后一個Button不填充剩余空間"></Button>
</DockPanel>
</Window>
到此這篇關(guān)于WPF使用DockPanel??棵姘宀季值奈恼戮徒榻B到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
-
.net core 6.0 通過依賴注入注冊和使用上下文服務(wù)的教程
在.NET Core 6.0 中,獲取上下文的方式取決于您使用的技術(shù)棧和具體的應(yīng)用程序類型,這篇文章主要介紹了.net core 6.0 通過依賴注入注冊和使用上下文服務(wù)的教程,需要的朋友可以參考下 2023-12-12
-
國產(chǎn)化之銀河麒麟安裝.netcore3.1的詳細(xì)步驟(手動安裝)
這篇文章主要介紹了國產(chǎn)化之銀河麒麟安裝.netcore3.1的詳細(xì)步驟(手動安裝),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下 2022-03-03
-
asp.net編程獲取項(xiàng)目根目錄實(shí)現(xiàn)方法集合
這篇文章主要介紹了asp.net編程獲取項(xiàng)目根目錄實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析總結(jié)了asp.net針對項(xiàng)目目錄的操作技巧與注意事項(xiàng),需要的朋友可以參考下 2015-11-11
最新評論
DockPanel:??棵姘?/h2>
DockPanel定義一個區(qū)域,在此區(qū)域中,您可以使子元素通過描點(diǎn)的形式排列,這些對象位于 Children 屬性中。??棵姘孱愃朴赪inForm中控件的Dock屬性。DockPanel會對每個子元素進(jìn)行排序,并將根據(jù)指定的邊進(jìn)行??浚鄠€??吭谕瑐?cè)的元素則按順序排序。在DockPanel中,指定停靠邊的控件,會根據(jù)定義的順序占領(lǐng)邊角,所有控件絕不會交疊。
默認(rèn)情況下,后添加的元素只能使用剩余空間,無論對DockPanel的最后一個子元素設(shè)置任何停靠值,該子元素都將始終填滿剩余的空間。如果不希望最后一個元素填充剩余區(qū)域,可以將DockPanel屬性LastChildFill設(shè)置為false,還必須為最后一個子元素顯式指定??糠较?。
1、填充整個剩余空間
使用XAML代碼實(shí)現(xiàn):
<Window x:Class="WpfDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DockPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen"> <DockPanel> <Button DockPanel.Dock="Left" Content="ButtonLeft"></Button> <Button DockPanel.Dock="Top" Content="ButtonTop"></Button> <Button DockPanel.Dock="Right" Content="ButtonRight"></Button> <Button DockPanel.Dock="Bottom" Content="ButtonBottom"></Button> <Button Content="ButtonTop"></Button> </DockPanel> </Window>
2、最后元素不填充剩余空間
使用XAML代碼實(shí)現(xiàn):
<Window x:Class="WpfDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DockPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen"> <DockPanel LastChildFill="False"> <Button DockPanel.Dock="Left" Content="ButtonLeft"></Button> <Button DockPanel.Dock="Top" Content="ButtonTop"></Button> <Button DockPanel.Dock="Right" Content="ButtonRight"></Button> <Button DockPanel.Dock="Bottom" Content="ButtonBottom"></Button> <Button DockPanel.Dock="Top" Content="最后一個Button不填充剩余空間"></Button> </DockPanel> </Window>
到此這篇關(guān)于WPF使用DockPanel??棵姘宀季值奈恼戮徒榻B到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
.net core 6.0 通過依賴注入注冊和使用上下文服務(wù)的教程
在.NET Core 6.0 中,獲取上下文的方式取決于您使用的技術(shù)棧和具體的應(yīng)用程序類型,這篇文章主要介紹了.net core 6.0 通過依賴注入注冊和使用上下文服務(wù)的教程,需要的朋友可以參考下2023-12-12國產(chǎn)化之銀河麒麟安裝.netcore3.1的詳細(xì)步驟(手動安裝)
這篇文章主要介紹了國產(chǎn)化之銀河麒麟安裝.netcore3.1的詳細(xì)步驟(手動安裝),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03asp.net編程獲取項(xiàng)目根目錄實(shí)現(xiàn)方法集合
這篇文章主要介紹了asp.net編程獲取項(xiàng)目根目錄實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析總結(jié)了asp.net針對項(xiàng)目目錄的操作技巧與注意事項(xiàng),需要的朋友可以參考下2015-11-11