欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WPF使用StackPanel棧面板布局

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

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

面板(Panel)

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

StackPanel:棧面板

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

1、垂直方向排列

界面運行效果:

使用XAML代碼實現(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="第一個"></Button>
        <Button Content="第二個"></Button>
        <Button Content="第三個"></Button>
        <Button Content="第四個"></Button>
    </StackPanel>
</Window>

2、水平方向排列

界面運行效果:

使用XAML代碼實現(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="第一個"></Button>
        <Button Content="第二個"></Button>
        <Button Content="第三個"></Button>
        <Button Content="第四個"></Button>
    </StackPanel>
</Window>

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

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

相關(guān)文章

最新評論