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);
        }
    }
}

 

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • AWVS工具介绍[通俗易懂]

    AWVS工具介绍[通俗易懂]AWVS基本操作  AWVS工具在网络安全行业中占据着举足轻重的地位,作为一名安全服务工程师,AWVS这款工具在给安全人员做渗透测试工作时带来了巨大的方便,大大的提高了工作效率。AWVS工具介绍  AcunetixWebVulnerabilityScanner(简称AWVS)是一款知名的Web网络漏洞扫描工具,它通过网络爬虫测试你的网站安全,检测流行安全漏洞。它包含有收费和免…

  • PyCharm激活码永久有效PyCharm2017.1.8激活码教程-持续更新,一步到位

    PyCharm激活码永久有效PyCharm2017.1.8激活码教程-持续更新,一步到位PyCharm激活码永久有效2017.1.8激活码教程-Windows版永久激活-持续更新,Idea激活码2017.1.8成功激活

  • 数组拼接sql语句[通俗易懂]

    数组拼接sql语句[通俗易懂]数组如何拼接sql语句前端回参为数组的话,不能直接用来拼接sql查询,得经过处理,将其一个个拼入sql语句documentType={1,2,3}StringBuilderquerysql=newStringBuilder(“fromT_BUS_BALANCE_BILLtbbbLEFTJOINT_BUS_ACCOUNT_BILLcONtbbb.ID=c.IDwhere1=1”);if(documentType!=null&&

  • python中关于input和raw_input的使用方法「建议收藏」

    python中关于input和raw_input的使用方法「建议收藏」input和raw_input的区别:input和raw_input都可以读取控制台的输入,但是raw_input和input在处理数字和字符串是有区别的输入纯数字时raw_input返回类型

  • 软件测试用例模板

    软件测试用例模板软件测试用例模板

  • 深度学习中的迁移学习介绍[通俗易懂]

    迁移学习(TransferLearning)的概念早在20世纪80年代就有相关的研究,这期间的研究有的称为归纳研究(inductivetransfer)、知识迁移(knowledgetransfer)、终身学习(life-longlearning)以及累积学习(incrementallearning)等。直到2009年,香港科技大学杨强教授对迁移学习的研究进行了总结和归纳,迁移学习才开始有了较为完善的框架和基本概念。迁移学习的研究范围和研究领域非常广泛。推荐学习迁移学习一个非常好的资源:htt

发表回复

您的电子邮箱地址不会被公开。

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