WPF中ListBox的样式设置
设置之后的效果为
1 窗体中代码
<Window x:Class="QyNodeTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style/Style.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ListBox Style="{StaticResource ListBoxHor}">
<ListBoxItem>
<Border>
<StackPanel>
<TextBlock HorizontalAlignment="Center">项目1</TextBlock>
<Button Content="OK" Width="80" HorizontalAlignment="Center"/>
</StackPanel>
</Border>
</ListBoxItem>
<ListBoxItem>
<Border>
<StackPanel>
<TextBlock HorizontalAlignment="Center">项目1</TextBlock>
<Button Content="OK" Width="80" HorizontalAlignment="Center"/>
</StackPanel>
</Border>
</ListBoxItem>
<ListBoxItem>
<Border>
<StackPanel>
<TextBlock HorizontalAlignment="Center">项目1</TextBlock>
<Button Content="OK" Width="80" HorizontalAlignment="Center"/>
</StackPanel>
</Border>
</ListBoxItem>
<ListBoxItem>
<Border>
<StackPanel>
<TextBlock HorizontalAlignment="Center">项目1</TextBlock>
<Button Content="OK" Width="80" HorizontalAlignment="Center"/>
</StackPanel>
</Border>
</ListBoxItem>
</ListBox>
</Grid>
</Window>
2 样式文件中代码
<!--设置ListBox样式-->
<Style TargetType="ListBox" x:Key="ListBoxHor">
<!--设置模板-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<WrapPanel Orientation="Horizontal" IsItemsHost="True" ScrollViewer.CanContentScroll="True"/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--设置ListBoxItem样式-->
<Style TargetType="ListBoxItem">
<Setter Property="Width" Value="120"></Setter>
<Setter Property="Height" Value="40"></Setter>
<Setter Property="Margin" Value="5"></Setter>
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="1"/>
<!--设置控件模板-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextBlock.Foreground="{TemplateBinding Foreground}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!--设置触发器-->
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="#808080"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderBrush" Value="Green"/>
<Setter Property="BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Red"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="2"/>
</Trigger>
</Style.Triggers>
</Style>
WPF中ListBox的样式设置的更多相关文章
- WPF中ListBox滚动时的缓动效果
原文:WPF中ListBox滚动时的缓动效果 上周工作中遇到的问题: 常规的ListBox在滚动时总是一格格的移动,感觉上很生硬. 所以想要实现类似Flash中的那种缓动的效果,使ListBox滚动时 ...
- WPF中ListBox的项ListBoxItem被选中的时候Background变化
使用WPF 中ListBox,点击ListBoxItem的时候,自定义它的背景色,曾经在网上找了一些方法, 不是很理想,后来在StackOverflow上找到了,贴出代码和效果图: 效果图:
- 转:WPF中ListBox的创建和多种绑定用法
先从最容易的开始演示ListBox控件的创建. Adding ListBox Items下面的代码是向ListBox控件中添加多项ListBoxItem集合.XAML代码如下:<ListBox ...
- WPF中ListBox的绑定
WPF中列表式控件派生自ItemsControl类,继承了ItemsSource属性.ItemsSource属性可以接收一个IEnumerable接口派生类的实例作为自己的值(所有可被迭代遍历的集合都 ...
- WPF 中的style 样式
WPF相较于以前学的WinForm,WPF在UI设计与动画方面的炫丽是最吸引我来学习的.在WPF中XMAL代码的引入使得代码的编写能够前后端分离,为获得更好的界面,也使得我们不得不分出一半的时间花在前 ...
- WPF中未将对象引用设置到对象的实例
前几天,我开始了WPF的基础学习,一上来我就遇到了一个令我头痛的问题,按照书上的例子我写了一段属于自己的代码,一个简单的色调器.满心期待的编译运行,就出现了未将对象引用设置到对象的实例.我在网上查阅了 ...
- WPF中ListBox /ListView如何改变选中条背景颜色
适用ListBox /ListView WPF中LISTVIEW如何改变选中条背景颜色 https://www.cnblogs.com/sjqq/p/7828119.html
- WPF中ListBox ListView数据翻页浏览笔记(强调:是数据翻页,非翻页动画)
ListBox和ListView在应用中,常常有需求关于每页显示固定数量的数据,然后通过Timer自动或者手动翻页操作,本文介绍到的就是该动作的实现. 一.重点 对于ListBox和ListView来 ...
- WPF教程十:如何使用Style和Behavior在WPF中规范视觉样式
在使用WPF编写客户端代码时,我们会在VM下解耦业务逻辑,而剩下与功能无关的内容比如动画.视觉效果,布局切换等等在数量和复杂性上都超过了业务代码.而如何更好的简化这些编码,WPF设计人员使用了Styl ...
随机推荐
- Struts2 + Spring + Hibernate
Struts2 + Spring + Hibernate整合. 使用的是无配置方法进行SSH的整合,struts-convertion plugin + spring annotation + hib ...
- 全景VR视频外包公司:长年承接VR全景视频外包(技术分享YouTube的360全景视频)
虽然比预期来得晚了些,但YouTube终于支持360度全景视频了,这应该会吸引不少VR(虚拟现实)爱好者.今年1月,Google就表示这一功能将在“接下来”的几周出现.现在YouTube上已经有了一些 ...
- 测试工具之Charles视频教程(更新中。。。)
应群里小伙伴学习需求,录制新版 Charles V4 系列教程,后续内容抽空更新,测试工具系列带你上王者...(ノ°ο°)ノ前方高能预警 链接:http://pan.baidu.com/s/1c16P ...
- jsp中的<jsp:setProperty>中的param属性
比如: <jsp:setProperty name="lader" property="edge" param="num" /> ...
- sql语句,怎么查看一个表中的所有约束
sql语句,怎么查看一个表中的所有约束,比如,一个student表,有唯一,外键,主键,用sql语句怎么查看student表中的所有约束呢? select * from sysobjects wher ...
- AX 2012 SSRS print setting-报表打印输出设置
static void callerreport_printsetting(Args _args) { LedgerJournalController controller = new LedgerJ ...
- AX dynamics 2012 ssrs 开发报错:Native compiler return value: ‘[BC30179]
具体报错内容如下: System.Web.Services.Protocols.SoapException: An unexpected error occurred while compiling ...
- zhuang 定制iOS 7中的导航栏和状态栏
近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这也就意味着导航栏 ...
- 云存储性能测试工具--COSBench安装
COSBench安装 Cosbench是Intel的开源云存储性能测试软件,COSBench目前已经广泛使用与云存储测试,并作为云存储的基准测试工具使用 1 环境 1.1 操作系统 COSBench可 ...
- ASPxSpinEdit 控件的三元判断
方法一:<dx:ASPxSpinEdit ID=" DisplayFormatString="c" Width="100px"></ ...