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


相关推荐

  • Apache Struts2远程代码执行漏洞(CVE-2021-31805)安全通告[通俗易懂]

    Apache Struts2远程代码执行漏洞(CVE-2021-31805)安全通告[通俗易懂]1.事件描述监测发现,开源应用框架ApacheStruts存在远程代码执行漏洞(CVE-2021-31805),攻击者可构造恶意的OGNL表达式触发漏洞,实现远程代码执行。受影响版本为ApacheStruts2.0.0~2.5.29。目前,该漏洞已在ApacheStruts2.5.30版本中修复。事件类型:漏洞利用事件等级:高危2.影响范围远程代码执行漏洞影响范围:2.0.0<=ApacheStruts<=2.5.29不受影响版本ApacheStruts

    2022年7月13日
    19
  • menuconfig 语法

    menuconfig 语法menuconfig语法在Kconfig中定义的配置宏,前缀都没有CONFIG_,只有编译内核时,自动生成autoconf.h才会出现前缀.如果XX_defconfig板卡配置文件中定义新的宏=y时,而在Kconfig并没有声明它,则内核编译出来的autoconf.h里也不会定义它的.如果XX_defconfig板卡配置文件中没有设置CONFIG_MODULES=y则编译makemodules时将会失败,而m

    2022年6月9日
    51
  • mac版本idea激活码2021(最新序列号破解)

    mac版本idea激活码2021(最新序列号破解),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月19日
    224
  • wp和uwp_uwp wpf

    wp和uwp_uwp wpf一、异步调用之后,要更新UI时,代码如下二、原来的ApplicationBar更改为CommandBar三、原来在wp8.1中状态栏StatusBar类在UWP中也发生了改变现在要控制UWP状态

    2022年8月5日
    14
  • MacOS安装与卸载JDK

    MacOS安装与卸载JDK文章目录1.下载JDK8安装文件2.安装JDK文件2.1双击pkg文件安装即可2.2查看JDK安装位置2.3确定jdk安装完整3.配置JDK环境变量3.1打开终端窗口,打开基础配置文件3.2配置java环境变量3.3激活配置3.4输入javac和javap看是否安装成功1.下载JDK8安装文件链接:https://pan.baidu.com/s/1fbYP1M38aPwK…

    2022年6月25日
    28
  • android之layout_weight体验(实现按比例显示)

    在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示。android并没用提供table这样的控件,虽然有TableLayout,但是它并非是我们想象中的像html里面的table那么好用,我们常用ListView实现table的效果,但是列对齐确比较麻烦,现在用Linear

    2022年3月9日
    56

发表回复

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

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