首先定义一个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样式的更多相关文章

  1. WPF - Group分组对ListBox等列表样式的约束

    原文:WPF - Group分组对ListBox等列表样式的约束 在做WPF主题支持时,出现一个分组引起的莫名错误,可是折腾了我一番.在没有使用样式时,列表分组很正常,使用了别人写的ListBox列表 ...

  2. CSS3 更改字体被选中样式

    CSS3  更改字体被选中样式

  3. WPF中修改ListBox项的样式病修改选中项的背景颜色

    最终效果: 1 <ListBox Name="cmb"> 2 <!--修改颜色--> 3 <ListBox.Resources> 4 <! ...

  4. Typora/VSCode/Sublime 更改Markdown默认宽度样式等

    Typora 所见即所得Markdown编辑器更改 最大宽度 C:\Users\Desk\AppData\Roaming\Typora\themes\github.css CSS第46行改为 max- ...

  5. PyCharm更改字体和界面样式

    更改主题 File → Settings → Appearance & Behavior → Appearance → Theme 结果: 更改字体大小 File → Settings → E ...

  6. WPF ListView ListBox 常用的样式记录

    ListView: <ListView x:Name="lvBlockedApps" ItemsSource="{Binding BlockedAppsCollec ...

  7. WPF:自定义ListBox的选择样式

    首先介绍一种简单地方法:就是通过自定义SystemColors类的参数来自定义WPF ListBox选择颜色的, SystemColors的HighlightBrushKey和HighlightTex ...

  8. 自定义WPF ListBox的选择样式

    (下图:进行多项选择的ListBox) 首先介绍一种简单地方法:就是通过自定义SystemColors类的参数来自定义WPF ListBox选择颜色的,SystemColors的HighlightBr ...

  9. Change Style of Navigation Items 更改导航项的样式

    In this lesson, you will learn how to change the style of navigation items in a WinForms XAF applica ...

随机推荐

  1. MySQL主从同步原理

    mysql主从复制用途 实时灾备,用于故障切换 读写分离,提供查询服务 备份,避免影响业务 主从部署必要条件 主库开启binlo日志(设置log-bin参数) 主从server-id不同 从库可以连同 ...

  2. 图、dfs、bfs

    graphdfsbfs 1.clone graph2.copy list with random pointer3.topological sorting4.permutations5.subsets ...

  3. git fork之如何同步更新

    1.打开git fork的开源项目(这里我以git fork vscode为例): 2.点击New pull request 3.选择你自己的 4.选择完后出现如图 5.调整状态,右边改为源fork地 ...

  4. nginx做负载均衡和tomcat简单集群

    Nginx做负载均衡和TOMCAT简单集群                1.下载安装nginx及其依赖包                                               ...

  5. 编写简单Linux内核模块

    模块代码如下 //main.c #include <linux/kernel.h> #include <linux/module.h> #include <linux/i ...

  6. ASP.NET ActiveMQ 消息队列

    1.引入 2.发送消息 3.接收消息 概述:MQ消息存放在内存,重启后,消息丢失.接收后,消息丢失(只取一次),不取,一直在且速度快. 使用前:下载apache-activemq-5.15.2-bin ...

  7. kubernetes集群中对多个pod操作命令

    $ for i in 0 1; do kubectl exec web-$i -- sh -c 'echo hello $(hostname) > /usr/share/nginx/html/i ...

  8. Ionic下的JPush缺少统计代码问题解决方法

    用Ionic打包apk后安装到手机,收到缺少统计代码的提示,解决方法如下: 1. 找到了 platforms/android/src/com/ionichina/ioniclub/MainActiov ...

  9. Kafka:Configured broker.id 2 doesn't match stored broker.id 0 in meta.properties.

    在安装Kafka集群的时候,碰到这个问题. 我们知道在搭建Kafka集群的时候,我们需要设置broker.id,以作为当前服务器在整个集群的唯一标志. 网上搜查资料是说,log.dirs目录下的met ...

  10. libgdx学习记录26——Polygon多边形碰撞检测

    libgdx中Math封装了Polygon这个类,它是由多个定点进行描述实现的,在进行物体间的碰撞时,物体轮廓有时候是不规则的,这时候可以用一个多边形勾勒出其大概的轮廓,对其进行模拟. Polygon ...