WPF基础五:UI①布局元素WrapPanel[通俗易懂]

WPF基础五:UI①布局元素WrapPanel[通俗易懂]目录WrapPanelWrapPanel类XAML范例:C#代码WrapPanel按从左到右的顺序位置定位子元素,在包含框的边缘处将内容切换到下一行。后续排序按照从上至下或从右至左的顺序进行,具体取决于Orientation属性的值。WrapPanel包含UIElement对象的集合,这些对象位于Children属性中。WrapPanel的所有子元素都接收ItemWidth与ItemHeight大小相乘的布局分区。WrapPanel类名称…

大家好,又见面了,我是你们的朋友全栈君。

目录

 

WrapPanel

WrapPanel类

XAML范例:

C#代码


WrapPanel

按从左到右的顺序位置定位子元素,在包含框的边缘处将内容切换到下一行。 后续排序按照从上至下或从右至左的顺序进行,具体取决于 Orientation 属性的值。

WrapPanel包含UIElement对象的集合  ,这些对象位于 Children 属性中。

 WrapPanel 的所有子元素都接收ItemWidth 与ItemHeight大小相乘的布局分区 。


WrapPanel类

名称 备注 权限
ItemHeightProperty 标识 ItemHeight 依赖项属性 public
ItemWidthProperty 标识 ItemWidth 依赖项属性 public
OrientationProperty 标识 Orientation 依赖项属性 public
名称 备注 权限
ItemHeight 获取或设置一个值,该值指定 WrapPanel 中所含全部项的高度 public
ItemWidth 获取或设置一个值,该值指定 WrapPanel 中所含全部项的宽度 public
Orientation 获取或设置一个值,该值指定子内容的排列方向 public
名称 备注 权限
ArrangeOverride 获取或设置网格中的列数 public
MeasureOverride 获取或设置网格第一行中前导空白单元格的数量 public

XAML范例:

<Window x:Class="WrapPanel.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WrapPanel"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <WrapPanel ItemHeight="120" ItemWidth="200" Orientation="Vertical">
            <Button Content="Btn1" />
            <Button Content="Btn2" />
            <Button Content="Btn3" />
            <Button Content="Btn4" />
        </WrapPanel>
    </Grid>
</Window>

WPF基础五:UI①布局元素WrapPanel[通俗易懂]

Orientation=”Horizontal”

WPF基础五:UI①布局元素WrapPanel[通俗易懂]


当宽度或长度不一的时候,可以利用HorizontalAlignment或VerticalAlignment。

<Window x:Class="WrapPanel.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WrapPanel"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <WrapPanel ItemHeight="120" ItemWidth="200" Orientation="Vertical">
            <Button Content="Btn1" />
            <Button Content="Btn2" Width="100" HorizontalAlignment="Left"/>
            <Button Content="Btn3" Width="100" HorizontalAlignment="Right"/>
            <Button Content="Btn4" />
        </WrapPanel>
    </Grid>
</Window>

WPF基础五:UI①布局元素WrapPanel[通俗易懂]


C#代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WrapPanelDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            WrapPanel wrapPanel = new WrapPanel();

            for (int i = 1; i < 9; i++)
            {
                Button button = new Button();
                button.Content = "Btn" + (i);
                wrapPanel.Children.Add(button);
            }
            wrapPanel.Orientation = Orientation.Horizontal;
            wrapPanel.ItemHeight = 120;
            wrapPanel.ItemWidth = 200;

            ((this as Window).Content as Grid).Children.Add(wrapPanel);
        }
    }
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/163345.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • c 语言加壳项目,C 加壳工具,快速完成加密保护

    c 语言加壳项目,C 加壳工具,快速完成加密保护当前C#.net语言的应用范围越来越广泛,IIS的服务器架构后台代码、桌面应用程序的winform、Unity3d的逻辑脚本都在使用。C#.net具备强大的便捷特性,使得开发成本极低。而作为一款.net语言,也有它让开发者头疼的弊病——非常容易被反编译。市面上的Dnspy,ILspy,de4dot等工具可以非常容易反编译出被混淆保护的C#.net程序。01解决方案深思自主研…

    2022年6月27日
    39
  • Redis在Centos7上的安装部署[通俗易懂]

    Redis在Centos7上的安装部署

    2022年3月5日
    35
  • 1146 Topological Order「建议收藏」

    1146 Topological Order「建议收藏」题目题意:在给定有向图中,对于给定查询序列是否是有向图中的一个拓扑序列,记录非法序列下标tip:模拟拓扑排序#include<iostream>#include<vector>usingnamespacestd;intin_num[1003]={0};inttemp[1003]={0};vector<int>s[1003…

    2022年6月3日
    31
  • 用于安装python第三方库的工具是_Python第三方库安装

    用于安装python第三方库的工具是_Python第三方库安装Python 有一个全球社区 在这里 我们可以搜索 Python 第三方库的任何话题 PyPI 的全称是 Python 包指数指 Python 包的指数 它是由 PSF Python 软件基金会 和显示全球 Python 计算生态系统 我们需要学会使用 PyPI 的主要网站 搜索和发现我们使用第三方 Python 库和关心 例如 如果您正在开发一个 blockchain related 程序 您需要使用 Python 的计算生态三个步

    2025年7月3日
    3
  • 矩阵特征值和特征向量怎么求_矩阵的特征值例题详解

    矩阵特征值和特征向量怎么求_矩阵的特征值例题详解设A是n阶方阵,如果存在数m和非零n维列向量 x,使得Ax=mx成立,则称m是A的一个特征值(characteristicvalue)或本征值(eigenvalue)。非零

    2022年8月5日
    5
  • Java面对对象编程(超详细)

    Java面对对象编程(超详细)1、成员变量和成员方法成员变量(又叫属性,字段)成员方法2、类和对象的内存分配机制Java内存的结构分析栈:一般存放基本数据类型(局部变量)堆:存放对象(Catcat,数组等)

    2022年7月2日
    26

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号