WPF初学之绘制自己需要的Slider(之二)
2014-09-11 10:11
169 查看
结合之前的样式,做了一下修改和美化,贴出来!!!
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!--Control colors.--> <Color x:Key="DisabledControlDarkColor">#FFC5CBF9</Color> <Color x:Key="ControlLightColor">#4D4D4D</Color> <Color x:Key="ControlMediumColor">#FF7381F9</Color> <Color x:Key="ControlDarkColor">#4D4D4D</Color> <Color x:Key="ControlMouseOverColor">#FF3843C4</Color> <Color x:Key="ControlPressedColor">#FF211AA9</Color> <Color x:Key="GlyphColor">#FF444444</Color> <Color x:Key="BorderLightColor">#FFCCCCCC</Color> <Color x:Key="BorderDarkColor">#FF444444</Color> <Color x:Key="DefaultBorderBrushDarkColor">Black</Color> <Color x:Key="SliderTrackDarkColor">#4D4D4D</Color> <!--StyleLeft--> <Style x:Key="StyleLeft" TargetType="{x:Type RepeatButton}"> <Style.Setters> <Setter Property="Background" > <Setter.Value> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <!--<GradientStop Color="LightBlue" Offset="0"/>--> <GradientStop Color="Red" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Height" Value="5"/> <!--<Setter Property="BorderBrush" Value="#4D4D4D"/> <Setter Property="BorderThickness" Value="0"></Setter> <Setter Property="Focusable" Value="False"/>--> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RepeatButton}"> <Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style.Setters> <Style.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop Color="LightBlue" Offset="0"/> <GradientStop Color="SkyBlue" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> <!--<StyleRight>--> <Style x:Key="StyleRight" TargetType="{x:Type RepeatButton}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="IsTabStop" Value="false" /> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RepeatButton}"> <Border Background="Transparent" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--ThumbStyleByImage--> <Style x:Key="ThumbStyleByImage" TargetType="{x:Type Thumb}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Height" Value="23" /> <Setter Property="Width" Value="23" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Thumb}"> <Ellipse x:Name="Ellipse" StrokeThickness="1"> <Ellipse.Fill> <SolidColorBrush Color="Green" ></SolidColorBrush> </Ellipse.Fill> </Ellipse> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--HSlider--> <ControlTemplate x:Key="HSlider" TargetType="{x:Type Slider}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TickBar x:Name="TopTick" SnapsToDevicePixels="True" Placement="Top" Height="4" Visibility="Collapsed"> <TickBar.Fill> <SolidColorBrush Color="{DynamicResource GlyphColor}" /> </TickBar.Fill> </TickBar> <Border x:Name="TrackBackground" Margin="0" CornerRadius="0" Height="5" Grid.Row="1" BorderThickness="0.5"> <Border.BorderBrush> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="{DynamicResource BorderLightColor}" Offset="0.0" /> <GradientStop Color="{DynamicResource BorderDarkColor}" Offset="1.0" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Border.BorderBrush> <Border.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="{DynamicResource ControlLightColor}" Offset="0.0" /> <GradientStop Color="{DynamicResource SliderTrackDarkColor}" Offset="1.0" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Border.Background> </Border> <Track Grid.Row="1" x:Name="PART_Track"> <Track.DecreaseRepeatButton> <RepeatButton Style="{StaticResource StyleLeft}" Command="Slider.DecreaseLarge" /> </Track.DecreaseRepeatButton> <Track.Thumb> <Thumb Style="{StaticResource ThumbStyleByImage}" /> </Track.Thumb> <Track.IncreaseRepeatButton> <RepeatButton Style="{StaticResource StyleRight}" Command="Slider.IncreaseLarge" /> </Track.IncreaseRepeatButton> </Track> <TickBar x:Name="BottomTick" SnapsToDevicePixels="True" Grid.Row="2" Fill="{TemplateBinding Foreground}" Placement="Bottom" Height="4" Visibility="Collapsed" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="TickPlacement" Value="TopLeft"> <Setter TargetName="TopTick" Property="Visibility" Value="Visible" /> </Trigger> <Trigger Property="TickPlacement" Value="BottomRight"> <Setter TargetName="BottomTick" Property="Visibility" Value="Visible" /> </Trigger> <Trigger Property="TickPlacement" Value="Both"> <Setter TargetName="TopTick" Property="Visibility" Value="Visible" /> <Setter TargetName="BottomTick" Property="Visibility" Value="Visible" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!--MainSlider--> <Style x:Key="MainSlider" TargetType="{x:Type Slider}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Style.Triggers> <Trigger Property="Orientation" Value="Horizontal"> <Setter Property="MinWidth" Value="104" /> <Setter Property="MinHeight" Value="21" /> <Setter Property="Template" Value="{StaticResource HSlider}" /> </Trigger> </Style.Triggers> </Style> </ResourceDictionary>
相关文章推荐
- WPF初学之绘制自己需要的Slider
- 你就是一个画家!你现在想绘制一幅画,但是你现在没有足够颜色的颜料。为了让问题简单,我们用正整数表示不同颜色的颜料。你知道这幅画需要的n种颜色的颜料,你现在可以去商店购买一些颜料,但是商店不能保证能供应所有颜色的颜料,所以你需要自己混合一些颜料。混合两种不一样的颜色A和颜色B颜料可以产生(A XOR B)这种颜色的颜料(新产生的颜料也可以用作继续混合产生新的颜色,XOR表示异或操作)。本着勤俭节约的
- 走进WPF系列学习之二 如何用WPF绘制与配置2D图形界面
- 一步步做一个自己的对话框类之二(绘制对话框)
- 走进WPF系列学习之二 如何用WPF绘制与配置2D图形界面
- 简化IT 敏捷自己 需要SOA---SOA业务平台(五)
- WPF Slider滑动条的颜色修改方法
- 做自己喜欢做的事,需要勇气,也需要能力
- 菜鸟之C语言初涉(初学编程之总结系列之二)
- 给大家分享网站源码有12.9G需要的自己去下载吧
- windows程序设计(12):绘制自己的控件
- VMware认证系列之二:帮您找到自己的VCP证书
- 如何针对自己的需要修改caffe的网络(Python)
- 自己写的一个用于解决DateTimePicker的值无法为Null的控件.不过有问题.需要请各位帮忙看一下问题出在哪.
- 需要有在纷乱的外部环境中学会用自己的脑袋思考问题和判断问题的能力
- 【OpenGL学习代码笔记之二】 三维空间中点的绘制
- 在WPF中自定义你的绘制(二)
- WPF2D绘制图形方法
- 初学Java三大框架集成需要掌握的基本配置[Spring,MyBatis,Struts]
- mavenRepository【maven仓库,全都是maven项目,自己可以在里面下载需要的jar包】