Template、ItemsPanel、ItemContainerStyle、ItemTemplate

原文:Template、ItemsPanel、ItemContainerStyle、ItemTemplate

先来看一张图(网上下的图,加了几个字)


实在是有够“乱”的,慢慢来理一下;

1、Template是指控件的样式

在WPF中所有继承自contentcontrol类的控件都含有此属性,(继承自FrameworkElementdl类的TextBlock等控件无)。Template用于定义控件结构(Visual Tree),和Style有点容易混淆,每个控件初始没有Style属性,而在WPF中所有的控件都有默认的Template。Style也做样式解释,但是它改变的只是控件原来的属性,比如长宽颜色之类的,而Template可以改变控件的形状外形,还可以根据需要往里面添加其他的控件来丰富当前的控件。Style可以用来定义一定范围内的所有对应控件的样式,所以平时多为两者结合使用。

<Style x:Key="ListBoxStyle1" TargetType="ListBox">
<Setter Property="Background" Value="#FFFFFFFF"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
//............相关代码</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
 

2、ItemsPanel是指控件的子项的布局样式,只有那些有item的控件才有此属性,如ListBox ,Combox,TreeView,DataGrid,TabelControl等,后面的两个也是如此。

eg:在不做设置的时候,ListBox的Item子项是纵向排列的,但是可以通过设置ItemPanell来实现横向排列或者其他更复杂的排列方式。

<ListBox >  
<ListBox.ItemsPanel>
<ItemsPanelTemplate><VirtualizingStackPanel Orientation="Horizontal"/>//横向排列
</ItemsPanelTemplate></ListBox.ItemsPanel>
</ListBox>

3、ItemContainerStyle是控件子项的样式,在ListBox里即ListBoxItem的Style属性,只是在ListBox设ItemContainerStyle表示当前控件的所有子项都默认了这个style,它的格式就是对应子项控件的Style。

<ListBox  ItemContainerStyle="{StaticResource  ListBoxItemStyle}">  <ListBoxItem /><ListBoxItem />
</ListBox>

<ListBox >  <ListBoxItem  Style="{StaticResource  ListBoxItemStyle}"/><ListBoxItem  Style="{StaticResource  ListBoxItemStyle}"/>
</ListBox>

等价,但是显然前者要方便很多。


4、ItemTemplate是控件子项的样式,说法和1里面的相同,用法和3里面的相同,即与子项的Template属性等价,但是这个显然也是比较方便的。



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389830.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

熊猫烧香分析报告_熊猫分析进行最佳探索性数据分析

熊猫烧香分析报告目录 (Table of Contents) Introduction 介绍 Overview 总览 Variables 变数 Interactions 互动互动 Correlations 相关性 Missing Values 缺失值 Sample 样品 Summary 摘要 介绍 (Introduction) There are countless ways to perform exploratory data analys…

2060. 同源字符串检测

2060. 同源字符串检测 原字符串由小写字母组成&#xff0c;可以按下述步骤编码&#xff1a; 任意将其 分割 为由若干 非空 子字符串组成的一个 序列 。 任意选择序列中的一些元素&#xff08;也可能不选择&#xff09;&#xff0c;然后将这些元素替换为元素各自的长度&#x…

vue中的data用return返回

为什么在大型项目中data需要使用return返回数据呢&#xff1f;答&#xff1a;不使用return包裹的数据会在项目的全局可见&#xff0c;会造成变量污染&#xff1b;使用return包裹后数据中变量只在当前组件中生效&#xff0c;不会影响其他组件。 1、在简单的vue实例中看到的Vue实…

白裤子变粉裤子怎么办_使用裤子构建构建数据科学的monorepo

白裤子变粉裤子怎么办At HousingAnywhere, one of the first major obstacles we had to face when scaling the Data team was building a centralised repository that contains our ever-growing machine learning applications. Between these projects, many of them shar…

ubuntu+anaconda+tensorflow 及相关问题

配置tensorflow部分参考&#xff1a;https://blog.csdn.net/XUTIAN1129/article/details/78997633 装完anaconda, source ~/.bashrc后, 可以直接 pip install tensorflow-gpu , 珍爱生命&#xff0c;远离bazel。但想要c/c调用tf的时候远离不了&#xff0c;还是得bazel编译安装t…

2022. 将一维数组转变成二维数组

2022. 将一维数组转变成二维数组 给你一个下标从 0 开始的一维整数数组 original 和两个整数 m 和 n 。你需要使用 original 中 所有 元素创建一个 m 行 n 列的二维数组。 original 中下标从 0 到 n - 1 &#xff08;都 包含 &#xff09;的元素构成二维数组的第一行&#xf…

支持向量机SVM算法原理及应用(R)

支持向量机SVM算法原理及应用&#xff08;R&#xff09; 2016年08月17日 16:37:25 阅读数&#xff1a;22292更多 个人分类&#xff1a; 数据挖掘实战应用版权声明&#xff1a;本文为博主原创文章&#xff0c;转载请注明来源。 https://blog.csdn.net/csqazwsxedc/article/detai…

mad离群值_全部关于离群值

mad离群值An outlier is a data point in a data set that is distant from all other observations. A data point that lies outside the overall distribution of the dataset. Or in a layman term, we can say, an outlier is something that behaves differently from th…

2057. 值相等的最小索引

2057. 值相等的最小索引 给你一个下标从 0 开始的整数数组 nums &#xff0c;返回 nums 中满足 i mod 10 nums[i] 的最小下标 i &#xff1b;如果不存在这样的下标&#xff0c;返回 -1 。 x mod y 表示 x 除以 y 的 余数 。 示例 1&#xff1a;输入&#xff1a;nums [0,1,2…

SpringBoot中各配置文件的优先级及加载顺序

我们在写程序的时候会碰到各种环境(开发、测试、生产)&#xff0c;因而&#xff0c;在我们切换环境的时候&#xff0c;我们需要手工切换配置文件的内容。这大大的加大了运维人员的负担&#xff0c;同时会带来一定的安全隐患。 为此&#xff0c;为了能更合理地重写各属性的值&am…

青年报告_了解青年的情绪

青年报告Youth-led media is any effort created, planned, implemented, and reflected upon by young people in the form of media, including websites, newspapers, television shows, and publications. Such platforms connect writers, artists, and photographers in …

post提交参数过多时,取消Tomcat对 post长度限制

1.Tomcat 默认的post参数的最大大小为2M&#xff0c; 当超过时将会出错&#xff0c;可以配置maxPostSize参数来改变大小。 从 apache-tomcat-7.0.63 开始&#xff0c;参数 maxPostSize 的含义就变了&#xff1a; 如果将值设置为 0&#xff0c;表示 POST 最大值为 0&#xff0c;…

2048. 下一个更大的数值平衡数

2048. 下一个更大的数值平衡数 如果整数 x 满足&#xff1a;对于每个数位 d &#xff0c;这个数位 恰好 在 x 中出现 d 次。那么整数 x 就是一个 数值平衡数 。 给你一个整数 n &#xff0c;请你返回 严格大于 n 的 最小数值平衡数 。 示例 1&#xff1a;输入&#xff1a;n …

bzoj1222: [HNOI2001]产品加工

一开始以为是费用流。。然后搞不出来&#xff0c;路牌是DP&#xff0c;想一想 f[i][j]表示加工到第i个产品&#xff0c;然后A用时j&#xff0c;B用时的最小值 那么f[i][j]max(f[i-1][j-a[i]],f[i-1][j]b[i],f[i-1][j-c[i]]c[i]) 滚掉一维美滋滋 #include<cstdio> #includ…

map(平均平均精度_客户的平均平均精度

map(平均平均精度Disclaimer: this was created for my clients because it’s rather challenging to explain such a complex metric in simple words, so don’t expect to see much of math or equations here. And remember that I try to keep it simple.免责声明 &#…

Sublime Text 2搭建Go开发环境,代码提示+补全+调试

本文在已安装Go环境的前提下继续。 1、安装Sublime Text 2 2、安装Package Control。 运行Sublime&#xff0c;按下 Ctrl&#xff08;在Tab键上边&#xff09;&#xff0c;然后输入以下内容&#xff1a; import urllib2,os,hashlib; h 7183a2d3e96f11eeadd761d777e62404 e330…

629. K个逆序对数组

629. K个逆序对数组 给出两个整数 n 和 k&#xff0c;找出所有包含从 1 到 n 的数字&#xff0c;且恰好拥有 k 个逆序对的不同的数组的个数。 逆序对的定义如下&#xff1a;对于数组的第i个和第 j个元素&#xff0c;如果满i < j且 a[i] > a[j]&#xff0c;则其为一个逆…

zookeeper、hbase常见命令

a) Zookeeper&#xff1a;帮助命令-help i. ls /查看zk下根节点目录 ii. create /zk_test my_data//在测试集群没有创建成功 iii. get /zk_test my_data//获取节点信息 iv. set / zk_test my_data//更改节点相关信息 v. delete /zk_test//删除节点信…

鲜活数据数据可视化指南_数据可视化实用指南

鲜活数据数据可视化指南Exploratory data analysis (EDA) is an essential part of the data science or the machine learning pipeline. In order to create a robust and valuable product using the data, you need to explore the data, understand the relations among v…

2049. 统计最高分的节点数目

2049. 统计最高分的节点数目 给你一棵根节点为 0 的 二叉树 &#xff0c;它总共有 n 个节点&#xff0c;节点编号为 0 到 n - 1 。同时给你一个下标从 0 开始的整数数组 parents 表示这棵树&#xff0c;其中 parents[i] 是节点 i 的父节点。由于节点 0 是根&#xff0c;所以 p…