`
jiasongmao
  • 浏览: 670733 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

ListBox(CheckListBox)样式

    博客分类:
  • WPF
阅读更多
样式代码:

<Application.Resources>
		<!--ListBox样式-->
		<Style TargetType="ListBox">
			<Setter Property="BorderBrush" Value="#BDD4F1"/>
			<Setter Property="BorderThickness" Value="1"/>
			<Setter Property="Background" Value="#F8F7F5"/>
			<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/>
			<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
			<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
			<Setter Property="VerticalContentAlignment" Value="Center"/>
		</Style>
		<!--ListBoxItem样式-->
		<Style TargetType="ListBoxItem">
			<Setter Property="Foreground" Value="#B5BABF"/>
			<Setter Property="OverridesDefaultStyle" Value="True"/>
			<Setter Property="Height" Value="24"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ListBoxItem">
						<Border Name="back" BorderBrush="#F8F7F5" BorderThickness="0,1,0,1">
							<Border.Background>
								<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
									<GradientBrush.GradientStops>
										<GradientStopCollection>
											<GradientStop Color="#F8F7F5" Offset="0.0"/>
											<GradientStop Color="#F8F7F5" Offset="0.5"/>
											<GradientStop Color="#F8F7F5" Offset="0.51"/>
											<GradientStop Color="#F8F7F5" Offset="1"/>
										</GradientStopCollection>
									</GradientBrush.GradientStops>
								</LinearGradientBrush>
							</Border.Background>
                            <CheckBox Margin="2,0,0,0" VerticalAlignment="Center" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsSelected,Mode=TwoWay}">
                                <ContentPresenter Margin="2"/>
                            </CheckBox>
                        </Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsSelected" Value="True">
								<Trigger.EnterActions>
									<BeginStoryboard>
										<Storyboard>
											<DoubleAnimation To="32" Duration="0:0:0.3" Storyboard.TargetProperty="Height"/>
											<ColorAnimation To="#F3C37C" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
											<ColorAnimation To="#952B00" Duration="0:0:0.2" Storyboard.TargetProperty="(ListBoxItem.Foreground).(SolidColorBrush.Color)" />
											<ColorAnimation To="#FFF" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
											<ColorAnimation To="#FFEF99" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
											<ColorAnimation To="#FFE13F" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)" />
											<ColorAnimation To="#FFF3B0" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[3].(GradientStop.Color)" />
										</Storyboard>
									</BeginStoryboard>
								</Trigger.EnterActions>
								<Trigger.ExitActions>
									<BeginStoryboard>
										<Storyboard>
											<DoubleAnimation BeginTime="0:0:0.4" Duration="0:0:0.2" Storyboard.TargetProperty="Height"/>
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetProperty="(ListBoxItem.Foreground).(SolidColorBrush.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[3].(GradientStop.Color)" />
										</Storyboard>
									</BeginStoryboard>
								</Trigger.ExitActions>
							</Trigger>
							<Trigger Property="IsMouseOver" Value="True">
								<Trigger.EnterActions>
									<BeginStoryboard>
										<Storyboard>
											<ColorAnimation To="#D8E6F5" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
											<ColorAnimation To="#617A98" Duration="0:0:0.2" Storyboard.TargetProperty="(ListBoxItem.Foreground).(SolidColorBrush.Color)" />
											<ColorAnimation To="#F6F9FD" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
											<ColorAnimation To="#E0EBF7" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
											<ColorAnimation To="#D7E5F6" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)" />
											<ColorAnimation To="#F6F9FD" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[3].(GradientStop.Color)" />
										</Storyboard>
									</BeginStoryboard>
								</Trigger.EnterActions>
								<Trigger.ExitActions>
									<BeginStoryboard>
										<Storyboard>
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetProperty="(ListBoxItem.Foreground).(SolidColorBrush.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)" />
											<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[3].(GradientStop.Color)" />
										</Storyboard>
									</BeginStoryboard>
								</Trigger.ExitActions>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</Application.Resources>


使用示例:
<ListBox Margin="19,32,21,40" Name="listBox1" SelectionMode="Multiple">
			<ListBoxItem>WPF界面设计技巧(7)—模拟电梯升降的缓动动画 (7-22 16:41)
            </ListBoxItem>
			<ListBoxItem>WPF界面设计技巧(6)—玩玩数字墨水手绘涂鸦 (7-19 01:20)
            </ListBoxItem>
			<ListBoxItem>WPF界面设计技巧(5)—自定义列表项呈现内容 (7-17 12:25)
            </ListBoxItem>
			<ListBoxItem>WPF界面设计技巧(4)—自定义列表项样式 (7-16 23:02)
            </ListBoxItem>
			<ListBoxItem>WPF界面设计技巧(3)—实现不规则动画按钮 (7-15 23:17)
            </ListBoxItem>
			<ListBoxItem>WPF界面设计技巧(2)—自定义漂亮的按钮样式 (7-15 01:56)
            </ListBoxItem>
			<ListBoxItem>WPF界面设计技巧(1)—不规则窗体图文指南 (7-13 22:24)
			</ListBoxItem>
		</ListBox>



文章来源:http://tech.ddvip.com/2008-11/122587530789359.html
分享到:
评论

相关推荐

    unichecklistbox.zip_CheckListBox_ListBox_zip

    本话题主要聚焦于一种特殊的控件组合——"CheckListBox",它将列表框(ListBox)的功能与复选框(CheckBox)结合在一起,提高了用户选择多项选项的便捷性。"unichecklistbox.zip"是一个压缩包文件,包含了一系列资源和源...

    4.4ListBox控件(打造带有复选框的ListBox)

    本教程将详细介绍如何在MFC中打造一个带有复选框的ListBox,即CheckListBox。 首先,我们要知道,标准的ListBox控件并不直接支持复选框,因此我们需要使用一个特殊的控件——CCheckListBox类。这个类是MFC对Windows...

    给VB的ListBox滚动条皮肤添加图片背景和渐变色

    在VB(Visual Basic)编程中,为控件如ListBox添加自定义皮肤,特别是滚动条的样式,可以提升应用程序的视觉效果。本主题聚焦于如何为ListBox的滚动条添加图片背景和颜色渐变,以实现更丰富的用户界面。下面将详细...

    checklistbox

    6. 自定义样式:开发者可以通过调整控件的样式和模板来自定义`CheckListBox`的外观,使其适应应用的界面设计。 在编程中,我们通常会遇到以下操作`CheckListBox`的常见任务: 1. 添加和移除项:使用`Items.Add()`...

    wpf中checklistbox和radiobutton绑定相关的代码

    这些库提供了额外的样式、动画或其他高级功能,以提升用户体验。 通过以上的知识讲解,你应该能够理解如何在WPF中使用 `CheckListBox` 和 `RadioButton`,并实现它们与数据模型的绑定。同时,也可以根据实际需求,...

    ListBoxItem失去焦点样式

    ListBoxItem失去焦点样式修改,自己可以手动修改颜色

    商业编程-源码-Csharp实例38 使用checklistBox.zip

    `CheckListBox`控件是.NET Framework中System.Windows.Forms命名空间的一部分,它结合了列表框(ListBox)和复选框(CheckBox)的功能。用户可以在列表中滚动查看多项选择,并通过单击每个项目旁边的复选框来选择或...

    CheckBoxDemo.zip

    CheckListBox控件是其中一种,它结合了列表框(ListBox)和复选框(CheckBox)的功能,允许用户在列表中选择一个或多个项目,并通过复选框来显示其选择状态。本示例"CheckBoxDemo.zip"显然提供了关于如何操作...

    asp.net 自制的单选、多选列表实现代码

    答:在ASP.NET的页面上,ListBox最终是渲染成select元素,而CheckListBox最终被渲染成div或者是table,使得二者的样式无法统一,或者说要统一很麻烦。 解决: 于是,决定干脆自行组合一些元素,实现单选列表、多选...

    Delphi使用

    Edit1.Text := ListBox1.Items.CommaText; Edit2.Text := ListBox1.Items.Text; Edit3.Text := ListBox1.Items.GetNamePath; Edit4.Text := ListBox1.Items.Strings[1]; Edit5.Text := ListBox1.Items....

    Visual_C++MFC入门教程

    - **4.5 ListBox/CheckListBox** - ListBox控件:学习如何使用ListBox控件创建列表框,支持单选或多选。 - CheckListBox控件:掌握使用CheckListBox控件创建带有复选框的列表框。 - **4.6 ComboBox/ComboBoxEx** ...

    wxPython 学习笔记

    - **构造函数**: `wx.CheckListBox(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, choices=[], style=0, validator=wx.DefaultValidator, name="checkListBox")` ##### 20. **wx.Choice** —— ...

    Visual_C++_6.0_MFC_入门教程-闻怡洋.pdf

    #### 4.5 ListBox/CheckListBox 列表框的使用,以及复选列表框的特殊功能。 #### 4.6 ComboBox/ComboBoxEx 组合框的使用,以及增强型组合框的额外功能。 #### 4.7 TreeCtrl 树状控件的使用,适用于展示层级结构...

    Delphippt 第八章讲解

    Panel的属性可以调整其外观和行为,例如,可以改变边框样式和颜色,设置面板的尺寸和位置。 列表框(ListBox)是显示单行文本列表的控件,用户可以选择一个或多个项目。CheckListBox是列表框的一个变体,它允许用户...

    Delphi专业 界面 控件Skin++ For Delphi (一)

    带滚动条的控件有:Edit,Tmemo,ListBox,ComboBox(Dropdown,DropdownList,Simple), TStringGrid, CheckListBox,LabeledEdit,RichEdit,ColorListBox,ScrollBar(横向、纵向),TCategoryButtons,TValueListEditor,...

    Delphi 专业 界面 控件 Skin++ For Delphi(二)

    带滚动条的控件有:Edit,Tmemo,ListBox,ComboBox(Dropdown,DropdownList,Simple), TStringGrid, CheckListBox,LabeledEdit,RichEdit,ColorListBox,ScrollBar(横向、纵向),TCategoryButtons,TValueListEditor,...

    计算机c++mfc入门教程

    - **4.5 ListBox/CheckListBox** - **4.6 ComboBox/ComboBoxEx** - **4.7 TreeCtrl** - **4.8 ListCtrl** - **4.9 TabCtrl** - **4.A ToolBar** - **4.B StatusBar** - **4.C DialogBar** - **4.D 利用AppWizard创建...

Global site tag (gtag.js) - Google Analytics