亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

WPF使用StackPanel棧面板布局

 更新時(shí)間:2022年02月25日 10:41:17   作者:.NET開(kāi)發(fā)菜鳥  
這篇文章介紹了WPF使用StackPanel棧面板布局的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

應(yīng)用程序界面設(shè)計(jì)中,合理的元素布局至關(guān)重要,它可以方便用戶使用,并將信息清晰合理地展現(xiàn)給用戶。WPF提供了一套功能強(qiáng)大的工具-面板(Panel),來(lái)控制用戶界面的布局。你可以使用這些面板控件來(lái)排布元素。如果內(nèi)置布局控件不能滿足需要的話,還可以創(chuàng)建自定義的布局元素。

面板(Panel)

WPF用于布局的面板主要有6個(gè),StackPanel(棧面板)、WrapPanel(環(huán)繞面板)。DockPanel(??棵姘澹?、Canvas(畫布)、Grid(網(wǎng)格面板)和UniformGrid(均布網(wǎng)格)。

StackPanel:棧面板

棧面板,可以將元素排列成一行或者一列,其特點(diǎn)是:每個(gè)元素各占一行或者一列,Orientation屬性指定排列方式:Vertical(垂直)【默認(rèn)】、Horizontal(水平),默認(rèn)情況下,水平排列時(shí),每個(gè)元素都與面板一樣高;垂直排列時(shí),每個(gè)元素都與面板一樣寬。如果包含的元素超過(guò)了面板空間,它只會(huì)截?cái)喽喑龅膬?nèi)容。 元素的Margin屬性用于使元素之間產(chǎn)生一定得間隔,當(dāng)元素空間大于其內(nèi)容的空間時(shí),剩余空間將由HorizontalAlignment和 VerticalAlignment屬性來(lái)決定如何分配。

1、垂直方向排列

界面運(yùn)行效果:

使用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="StackPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen">
    <StackPanel x:Name="stackpanel" Margin="0" Orientation="Vertical">
        <Button Content="第一個(gè)"></Button>
        <Button Content="第二個(gè)"></Button>
        <Button Content="第三個(gè)"></Button>
        <Button Content="第四個(gè)"></Button>
    </StackPanel>
</Window>

2、水平方向排列

界面運(yùn)行效果:

使用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="StackPanel面板" Height="237" Width="525" WindowStartupLocation="CenterScreen">
    <StackPanel x:Name="stackpanel" Margin="0" Orientation="Horizontal">
        <Button Content="第一個(gè)"></Button>
        <Button Content="第二個(gè)"></Button>
        <Button Content="第三個(gè)"></Button>
        <Button Content="第四個(gè)"></Button>
    </StackPanel>
</Window>

注:當(dāng)把StackPanel的FlowDirection屬性設(shè)置為RightToLeft,Orientation屬性設(shè)置為Horizontal,StackPanel將從右向左排列元素。

到此這篇關(guān)于WPF使用StackPanel棧面板布局的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論