WPF学习笔记(22)项面板模板ltemsPanelTemplate与三种模板总结

项面板模板ltemsPanelTemplate与三种模板总结


一、ltemsPanelTemplate

1.概述

ltemsPanelTemplate类是用于定义项控件(ItemsControl)的布局面板的一种模板,它允许开发人员自定义如何排列和呈现项控件中的子项

官方文档:https://learn.microsoft.com/zh-cn/dotnet/api/system.windows.controls.itemspaneltemplate?view=netframework-4.8

2. ItemsControl类

ItemsControl类是列表ListBox、下拉框ComboBox、菜单、网格DataGrid等一系列选项的基类,部分属性如下:

属性 说 明
ltemsSource 获取或设置用于生成 ltemsControl 的内容的集合。 设置ltemsSource属性后,集合ltems是只读且固定大小的,因此不可修改。
ltems 获取用于生成 ltemsControl 的内容的集合。
DisplayMemberPath 获取或设置源对象上的值的路径,以用作对象的可视表示形式,不能同时设置 DisplayMemberPath 和ltemTemplate.
ItemTemplate 获取或设置用来显示每个项的数据模板DataTemplate。
ltemContainerStyle 获取或设置应用于为每个项生成的容器元素的 Style。
ltemsPanel 获取或设置模板(ltemsPanelTemplate类型),该模板定义对项的布局进行控制的面板。

3. 示例


xml 复制代码
<Grid>
    <!--ItemsControl类的 ItemsPanel 属性是ItemsPanelTemplate类型-->
    <ListBox Margin="175,83,230,125">
        <!--使用ItemsPanel和布局-->
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <system:String>编程</system:String>
        <ContentControl>音乐</ContentControl>
        <ListViewItem>篮球</ListViewItem>
    </ListBox>
</Grid>

二、三种模板总结

官方文档:https://learn.microsoft.com/zh-cn/dotnet/api/system.windows.frameworktemplate?view=netframework-4.8



相关推荐
Xin_ye100869 小时前
第三章:内存泄漏的常见“案发现场”
c#·wpf
心平气和量大福大15 小时前
C#-WPF-UserControl-生命周期(加载 退出)
开发语言·c#·wpf
czhc114007566318 小时前
7.23:Claude code:注册->封表
wpf
心平气和量大福大1 天前
C#-WPF-控件-TextBox 数据绑定
开发语言·c#·wpf
listening7772 天前
HarmonyOS 6.1 全场景协同实战:从“单机”到“超级终端”的分布式重构
wpf
心平气和量大福大2 天前
C#-WPF-布局-Grid
c#·wpf·visual studio
心平气和量大福大3 天前
C#-WPF-Window主窗体
开发语言·c#·wpf
FuckPatience4 天前
Telerik UI for WPF 值不能为null。参数名:key
ui·wpf
lindexi4 天前
WPF 笔迹延迟优化从硬件到软件的全链路分析
wpf
weixin_727535625 天前
双Token认证体系深度拆解:Spring Security + JWT + Redis
redis·spring·wpf