继续聊WPF
下面看一个Tick控件的例子,这只是演示,Tick单独使用没有意义。
- <TickBar Height="15" Width="180" Ticks="10,35,50,70" Maximum="100"
- Minimum="0" Fill="DarkMagenta" Placement="Top" />
好了,现在我们可以自定义一个Slider,这个例子是水平的,它用一个Grid来布局,共三行,最上和最下行分别放一个TickBar用于显示刻度,中间放一个Track为主体部分。
为了能动态显示刻度值,我们把Slider的Value属性绑定到TextBlock的Text属性,这样,只要Slider控件的值发生改变,TextBlock中就能动态显示,前面我们说过了,WPF的属性系统都是依赖项属性,因此可以动态关联。
- <Window x:Class="Sample_TickBar.Win2"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Win2" Height="300" Width="550">
- <Window.Resources>
- <Style x:Key="StyleForRepeatButton" TargetType="{x:Type RepeatButton}">
- <Style.Setters>
- <Setter Property="Background">
- <Setter.Value>
- <LinearGradientBrush
- StartPoint="0.5,0"
- EndPoint="0.5,1">
- <GradientStop Color="LightGreen" Offset="0"/>
- <GradientStop Color="Yellow" Offset="1"/>
- </LinearGradientBrush>
- </Setter.Value>
- </Setter>
- <Setter Property="Height" Value="10"/>
- <Setter Property="BorderBrush" Value="Transparent"/>
- <Setter Property="Focusable" Value="False"/>
- </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>
- <ControlTemplate x:Key="tmpThumb" TargetType="{x:Type Thumb}">
- <Ellipse Name="e" Width="13" MinHeight="20" Fill="Blue"/>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="e" Property="Fill" Value="Red"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- <ControlTemplate x:Key="tmp" TargetType="{x:Type Slider}">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="auto"/>
- <RowDefinition Height="auto" MinHeight="25"/>
- <RowDefinition Height="auto"/>
- </Grid.RowDefinitions>
- <TickBar x:Name="top" Fill="Magenta" Grid.Row="0" HorizontalAlignment="Stretch"
- Placement="Top" Height="8"
- Visibility="Collapsed"/>
- <Track x:Name="PART_Track" Grid.Row="1" HorizontalAlignment="Stretch">
- <Track.IncreaseRepeatButton>
- <RepeatButton Style="{StaticResource StyleForRepeatButton}"
- Command="Slider.IncreaseLarge"/>
- </Track.IncreaseRepeatButton>
- <Track.DecreaseRepeatButton>
- <RepeatButton Style="{StaticResource StyleForRepeatButton}"
- Command="Slider.DecreaseLarge"/>
- </Track.DecreaseRepeatButton>
- <Track.Thumb>
- <Thumb Height="20" Template="{StaticResource tmpThumb}"/>
- </Track.Thumb>
- </Track>
- <TickBar x:Name="Bottom" Grid.Row="2" Fill="Magenta" HorizontalAlignment="Stretch"
- Visibility="Collapsed" Placement="Bottom" Height="8"/>
- </Grid>
- <ControlTemplate.Triggers>
- <Trigger Property="TickPlacement" Value="TopLeft">
- <Setter TargetName="top" Property="Visibility" Value="Visible"/>
- </Trigger>
- <Trigger Property="TickPlacement" Value="BottomRight">
- <Setter Property="Visibility" TargetName="Bottom" Value="Visible"/>
- </Trigger>
- <Trigger Property="TickPlacement" Value="Both">
- <Setter TargetName="top" Property="Visibility" Value="Visible"/>
- <Setter TargetName="Bottom" Property="Visibility" Value="Visible"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Window.Resources>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="50"/>
- <RowDefinition Height="auto"/>
- </Grid.RowDefinitions>
- <Slider x:Name="SliderTest" Grid.Row="0" Margin="10,5,10,5" Maximum="100" Minimum="0" TickFrequency="1"
- Template="{StaticResource tmp}"
- Value="20" TickPlacement="BottomRight"/>
- <TextBlock Grid.Row="1" Text="{Binding Path=Value,ElementName=SliderTest}"
- FontFamily="宋体" FontSize="24" FontWeight="Bold"
- Margin="150,0,150,0" HorizontalAlignment="Center"/>
- </Grid>
- </Window>
继续聊WPF的更多相关文章
- 继续聊WPF——获取ComboBox中绑定的值
千万不要认为WPF中的数据绑定会很复杂,尽管它的确比Winform程序灵活多了,但其本质是不变的,特别是ComboBox控件,我们知道在Winform中对该控件的有两个专为数据绑定而设定的属性——Di ...
- 继续聊WPF——如何获取ListView中选中的项
在WPF中获Listview中选中的项,与WinForm里面有着很大的区别,要亲身去研究一下在WPF中如果处理,其实也不难,来,下面我们一起来通过一个简单的示例来感悟一下吧. 第一步就是建立一个WPF ...
- 继续聊WPF——动态数据模板
我为啥称之为“动态数据模板”?先看看下面的截图,今天,我们就是要实现这种功能. 大概是这样的,我们定义的DataTemplate是通过触发器动态应用到 ComboBoxItem 上. 这个下拉列表控件 ...
- 继续聊WPF——设置网格控件列标题的样式
我很奇怪的是,微软那厮是怎么搞的,Blend里面居然不能编辑GridView的样式,十万般无奈之下,只好手写XAML来处理了. 要想知道一个控件的样式是如何设置,看控件类的定义很重要,我们来看看Gri ...
- 继续聊WPF——Thumb控件
这个控件,真不好介绍,MSDN上也是草草几句,反正就是可以让用户拖动的玩意儿,但是,你会发现,当你在该控件上拖动时,它没有反响,也就是说这个东西默认不做任何操作的,它是赖在那里什么都不干,除非你去踢上 ...
- 继续聊WPF——自定义CheckBox控件外观
上一篇文章中谈到了BulletDecorator控件,就是为自定义CheckBox控件的模板做准备,因为CheckBox需要比较严格的布局,正好,BulletDecorator控件就合适了,该控件的布 ...
- 继续聊WPF——进度条
ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值. 关键是它的控 ...
- 继续聊WPF——Expander控件(1)
这个控件最实用的地方,就是做导航栏. <StackPanel Margin="20,20" Width="100" Height="460&qu ...
- 继续聊WPF——为ListView的行设置样式
<Window x:Class="Wpf_GridHeaderStyle_sample.Window1" xmlns="http://schemas.microso ...
随机推荐
- iOS7系统iLEX RAT冬青鼠安装教程:无需刷机还原纯净越狱系统
全网科技 温馨提醒:iLEX RAT和Semi-Restore的作用都是让你的已越狱的设备恢复至越狱的初始状态. 可是要注意无论你是用iLexRAT冬青鼠还是Semi-restore.对于还原来说都存 ...
- HDU2037 事件排序问题
题目要求: Problem Description "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!&q ...
- Android WiFi开发教程(三)——WiFi热点数据传输
在上一篇文章中介绍了WiFi的搜索和连接,如果你还没阅读过,建议先阅读上一篇Android WiFi开发教程(二)——WiFi的搜索和连接.本篇接着简单介绍手机上如何通过WiFi热点进行数据传输. 跟 ...
- NYOJ15括号匹配
NYOJ15括号匹配 括号匹配(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:6 描述 给你一个字符串,里面只包含"(",")" ...
- linux随便贴贴
在bin目录下进入mysql: ./mysql -uroot -p123456 update mysql.user set password=password('root') where user=' ...
- Python 42 mysql用户管理 、pymysql模块
一:mysql用户管理 什么是mysql用户管理 mysql是一个tcp服务器,应用于操作服务器上的文件数据,接收用户端发送的指令,接收指令时需要考虑到安全问题, ATM购物车中的用户认证和mysql ...
- BZOJ 4010 拓扑排序+heap
思路: 反向图求最大拓扑序 反向输出 //By SiriusRen #include <queue> #include <cstdio> #include <cstrin ...
- 2015 多校赛 第四场 1010 (hdu 5336)
Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...
- HTML 简要概述
注: 说实在的,这门语言的确不需要太多或太详细的篇幅来大书特书.掌握个大概,知道些特点及特性也就差不多了.人脑不是电脑,不需要死记硬背许多的属性和值,有一本帮助手册在手,胜过千言万语. 什么是 HTM ...
- 7.union
联合结果集union 简单的结果集联合: select number,name,age from emp union select cardnumber,name,age from emp2 基本的原 ...