在 Windows 8 CP 中为选定的 ListViewItem 设置样式 [英] Styling a selected ListViewItem in Windows 8 CP

查看:13
本文介绍了在 Windows 8 CP 中为选定的 ListViewItem 设置样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变下图中所选项目的边框外观.

I want to change the appearance of the Border of the selected Item in the picture linked below.

我已经在 msdn.com 和互联网上四处寻找,但没有发现任何有用的东西.

I've already been looking around on msdn.com and on the internet, but I've found nothing useful.

我该怎么做?

推荐答案

选择外观是 ListViewItem 的 ControlTemplate 的一部分.要修改整个 ListView 的模板,请使用 ItemContainerStyle 将样式应用于每个项目,其中可以包含模板的修改版本.

The selection appearance is part of the ControlTemplate for ListViewItem. To modify the template for an entire ListView use the ItemContainerStyle to apply a Style to each item, which can contain a modified version of the template.

<ListView>
  <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ListViewItem">
            ...
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </ListView.ItemContainerStyle>
</ListView>

ListViewItem 的默认模板非常复杂,因此为了尽可能多地保留默认行为并为您提供一个良好的起点,使用 Blend 为您创建一个副本是最简单的.

The default template for ListViewItem is pretty complex so in order to preserve as much of the default behavior as possible and give you a good starting point, it's easiest to use Blend to create a copy for you.

在 Blend 中,右键单击您的 ListView 并选择:

In Blend, right-click your ListView and select:

编辑其他模板 -> 编辑生成的项目容器 -> 编辑副本...

它会在上面的表格中为您创建一个样式,并填充默认模板.选择外观使用模板中的几个不同元素,您可能想要修改这些元素 - 这些可以通过在中选择 Selected 状态来查看Blend 中的状态"面板并深入到对象"面板中突出显示的项目.

and it will create a Style for you in the form above with the default template filled in. The selection appearance uses a few different elements in the template which you may want to modify - these can be seen by selecting the Selected state in the States panel in Blend and drilling into the highlighted items in the Objects panel.

这篇关于在 Windows 8 CP 中为选定的 ListViewItem 设置样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆