关于更改ListBox的ItemsPanel样式
首先定义一个ListBoxItem的样式,用来显示相应的图片信息
<Style TargetType="{x:Type ListBoxItem}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="border" Height="64" Width="64" Margin="5,1,5,1" BorderThickness="2" VerticalAlignment="Center" Background="Aqua">
<Image Margin="5" Cursor="Hand" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding Photo}" ToolTip="{Binding Name}"> </Image>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="true" >
<Setter Property="BorderBrush" Value="Beige" TargetName="border"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" Value="BlanchedAlmond" TargetName="border"/>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="BorderBrush" Value="BurlyWood" TargetName="border"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
下面是更改ListBox的默认样式为,并且使用WrapPanel来展示图片,在使用的过程中需要注意一些方面。
<ListBox x:Name="myListBox" Margin="0,8,0,12" Grid.Row="1" Background="Transparent" BorderBrush="Transparent"
ItemsSource="{Binding MyPersonList}" ScrollViewer.CanContentScroll="False">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal">
</WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
通过修改ItemsPanelTemplate模板,我们能够使ListBox显示我们需要展示的东西,在这里需要注意一点的是上面是应用ListBoxItem的一种方式,还有下面一种方式,即在ListBox里添加一个x:Key="MyListBoxTemplate" 但是在下面进行引用的时候,必须使用
ItemContainerStyle="{StaticResource MyListBoxTemplate}" 进行引用,不能上面定义了Key而下面不使用ItemContainerStyle来进行引用,这样的话最终是不会为ListBoxItem添加样式的,所以必须成双成对的引用,这点我们需要注意,以上是自己使用的一点点心得体会。
关于更改ListBox的ItemsPanel样式的更多相关文章
- WPF - Group分组对ListBox等列表样式的约束
原文:WPF - Group分组对ListBox等列表样式的约束 在做WPF主题支持时,出现一个分组引起的莫名错误,可是折腾了我一番.在没有使用样式时,列表分组很正常,使用了别人写的ListBox列表 ...
- CSS3 更改字体被选中样式
CSS3 更改字体被选中样式
- WPF中修改ListBox项的样式病修改选中项的背景颜色
最终效果: 1 <ListBox Name="cmb"> 2 <!--修改颜色--> 3 <ListBox.Resources> 4 <! ...
- Typora/VSCode/Sublime 更改Markdown默认宽度样式等
Typora 所见即所得Markdown编辑器更改 最大宽度 C:\Users\Desk\AppData\Roaming\Typora\themes\github.css CSS第46行改为 max- ...
- PyCharm更改字体和界面样式
更改主题 File → Settings → Appearance & Behavior → Appearance → Theme 结果: 更改字体大小 File → Settings → E ...
- WPF ListView ListBox 常用的样式记录
ListView: <ListView x:Name="lvBlockedApps" ItemsSource="{Binding BlockedAppsCollec ...
- WPF:自定义ListBox的选择样式
首先介绍一种简单地方法:就是通过自定义SystemColors类的参数来自定义WPF ListBox选择颜色的, SystemColors的HighlightBrushKey和HighlightTex ...
- 自定义WPF ListBox的选择样式
(下图:进行多项选择的ListBox) 首先介绍一种简单地方法:就是通过自定义SystemColors类的参数来自定义WPF ListBox选择颜色的,SystemColors的HighlightBr ...
- Change Style of Navigation Items 更改导航项的样式
In this lesson, you will learn how to change the style of navigation items in a WinForms XAF applica ...
随机推荐
- day16 Python map函数
num_l=[1,2,10,5,3,7] #lambda x:x+1 # def add_one(x): # return x+1 #lambda x:x+1 # def reduce_one(x): ...
- node.js如何将远程的文件下载到本地、解压、读取
其实要解决的问题,很简单,获取远程文件,然后解压到本地读取. 在vscode中通过node.js来实现是比较方便的,相比之前的zip.js,我觉得我还是比较喜欢node.js实现方式. test.js ...
- Android学习之多触点滑动
知识点: 1.对矩阵:Matrix类熟悉,链接:https://blog.csdn.net/jdsjlzx/article/details/52741445 2.MotionEvent详解:https ...
- Linux 局域网同步时间
选择一台能上外网的机器作为时间服务器(都不能上亦可以,任选一台即可,但是只能保证局域网内时间同步) 配置此时间服务器 安装 ntp 在 /etc/ntp.conf 中配置 restrict 127.0 ...
- Redis 安装部署
1. 官网(https://redis.io/download)下载稳定版安装包 3.0.7或3.2或4.1; 2. 复制到部署服务器 /opt/redis4,解压 tar zxvf redis-4. ...
- RabbitMq、ActiveMq、ZeroMq、kafka之间的比较
MQ框架非常之多,比较流行的有RabbitMq.ActiveMq.ZeroMq.kafka.这几种MQ到底应该选择哪个?要根据自己项目的业务场景和需求.下面我列出这些MQ之间的对比数据和资料. 第一部 ...
- Spring @Scheduled定时任务的fixedRate,fixedDelay,cron执行差异
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import org.sp ...
- sql实时提交事务
public void deleteByHbtlidAndDept(String class_id,String depart_id) { Session session = this.getHibe ...
- OSC Source Code Innovation Salon(2018.10.20)
时间:2018.10.20地点:北京 朝阳 浦项中心B座2层
- iisapp -a命令出现 :此脚本不能与WScript工作
今天一个同事向我反馈,使用iis的命令时出现了如标题的问题. 通过百度,找到如下信息: iisapp实际上是存放在C:\windows \system32目录下的一个VBS脚本,全名为iisapp.v ...