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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ls 命令还能这么玩?看一下这 20 个实用范例

    ls 命令还能这么玩?看一下这 20 个实用范例

    2021年10月21日
    55
  • 目标检测与图像分割的区别_语义分割和实例分割最新论文

    目标检测与图像分割的区别_语义分割和实例分割最新论文计算机视觉的任务很多,有图像分类、目标检测、语义分割、实例分割和全景分割等,那它们的区别是什么呢?1、ImageClassification(图像分类)图像分类(下图左)就是对图像判断出所属的分类,比如在学习分类中数据集有人(person)、羊(sheep)、狗(dog)和猫(cat)四种,图像分类要求给定一个图片输出图片里含有哪些分类,比如下图的例子是含有person、sheep和do…

    2022年8月23日
    7
  • MYSQL分布式集群使用-主主复制「建议收藏」

    MYSQL分布式集群使用-主主复制

    2022年2月13日
    43
  • 非常详细的sklearn介绍

    非常详细的sklearn介绍0引言Sklearn(全称Scikit-Learn)是基于Python语言的机器学习工具。它建立在NumPy,SciPy,Pandas和Matplot…

    2022年5月13日
    41
  • python怎么表示取余_python如何实现取余操作[通俗易懂]

    python怎么表示取余_python如何实现取余操作[通俗易懂]python实现取余操作的方法:可以利用求模运算符(%)来实现。求模运算符可以将两个数相除得到其余数。我们还可以使用divmod()函数来实现取余操作,具体方法如:【divmod(10,3)】。在python中要实现取余操作可以使用求模运算符(%),该运算符可以将两个数相除得到其余数。(推荐教程:Python入门教程)如果一个数恰好能被另外一个数据整除,则余数为0,%运算后返回结果为0。可利用余数…

    2022年4月25日
    77
  • 如何免费申请博客 用WordPress建设网站

    如何免费申请博客 用WordPress建设网站如何用WordPress搭建博客  10年前左右开始兴起第一波互联网浪潮,博客作为一种新型的社交和阅读方式进入人们的视野,那一段时期是博客的黄金时代。现在,人们说“博客已死”。因为大概在7、8年前第二波互联网浪潮突然出现,且来势汹汹——移动互联网的时代到来了。人们被各种新型的社交媒体所吸引,单单手机APP就使人们忙的目不暇接。人们的选择越来越多,于是碎片化的娱乐逐渐成为人们社交休闲方式。人们不…

    2022年7月21日
    18

发表回复

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

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