WPF实现wp8样式的CheckBox
来源:互联网 发布:js框架 angularjs 编辑:程序博客网 时间:2024/05/01 12:11
效果很简单,直接上图
实现的方式很简单,直接上代码
<Window.Resources>
<!--当控件获得键盘焦点时的样式-->
<Style x:Key="FocusStyle">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Stroke="Red" StrokeThickness="1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--CheckBox样式-->
<Style TargetType="{x:Type CheckBox}">
<Setter Property="OverridesDefaultStyle" Value="False"></Setter>
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusStyle}"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<BulletDecorator FlowDirection="LeftToRight" VerticalAlignment="Center">
<BulletDecorator.Bullet>
<Border x:Name="bd" BorderThickness="1" BorderBrush="Red" MinHeight="15" MinWidth="15" VerticalAlignment="Center">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="LightGray" Offset="0.2"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Path x:Name="cp" Width="12" Height="12" Stroke="Blue" StrokeThickness="3"></Path>
</Border>
</BulletDecorator.Bullet>
<ContentPresenter Margin="5,0,0,0"/>
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="cp" Property="Data"
Value="M 0,6 L 6,12 12,0"/>
<Setter Property="Foreground" Value="LightGreen"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="bd" Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Orange" Offset="0.12"/>
<GradientStop Color="Yellow" Offset="0.92"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type CheckBox}" x:Key="wpStyle">
<Setter Property="OverridesDefaultStyle" Value="False"></Setter>
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusStyle}"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<BulletDecorator FlowDirection="LeftToRight" VerticalAlignment="Center">
<BulletDecorator.Bullet>
<Grid MinWidth="45" MinHeight="20">
<Rectangle Width="45" Height="15" Stroke="White" Fill="Black" x:Name="rc1" StrokeThickness="2"/>
<Rectangle Height="20" Width="15" Stroke="White" Fill="White" HorizontalAlignment="Left" x:Name="rc2"/>
</Grid>
</BulletDecorator.Bullet>
<ContentPresenter Margin="5,0,0,0"/>
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="rc1" Property="Fill" Value="Green"/>
<Setter TargetName="rc2" Property="HorizontalAlignment" Value="Right"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel Orientation="Vertical" Margin="20,20,20,20" Background="Black">
<CheckBox Content="苹果"/>
<CheckBox Content="鸡蛋"/>
<CheckBox Content="白菜"/>
<CheckBox Style="{StaticResource wpStyle}" Content="nihao" Margin="2,0,0,0"/>
</StackPanel>
这里要感谢某位姓周的大神吧,看到他的博文才想到的思路,感谢哈!
- WPF实现wp8样式的CheckBox
- 用WPF自定义CheckBox的样式
- WPF之CheckBox样式
- WPF的Treeview控件实现CheckBox
- 自定义RadioButton&CheckBox样式的实现
- 自定义RadioButton&CheckBox样式的实现
- wpf实现metrol风格的Treeview样式
- checkBox实现单选加样式
- WPF CheckBox 滑块 样式 开关
- 一个WP8样式的Android ProgressBar
- iTween.cs的WP8实现
- WPF实现带有Checkbox选择框的TreeView树控件
- 一步步学习WPF纯后台实现带checkbox的Treeview
- checkbox的样式
- 修改checkbox的样式
- 自定义样式的checkBox
- checkbox的样式优化
- checkBox的样式
- 分糖果(有疑问)
- System.exit(0)和System.exit(1)区别
- C语言const常见用法
- Android WebView开发问题及优化汇总
- 滑动翻页的实现5.1 拖拽结束接口
- WPF实现wp8样式的CheckBox
- CC1101 CRC校验位
- UIButton
- OC语言三大特性
- Picasso源码解析
- 浅析C#中const与readonly的区别
- 加油站(不会做)
- Unity3D鼠标控制摄像机“左右移动控制视角+WASD键盘控制前后左右+空格键抬升高度”脚本
- 在WebView中如何让JS与Java安全地互相调用