WPF RadioButton & CheckBox Style

<Style TargetType="CheckBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="CheckBox">
                        <Border x:Name="bd" BorderBrush="Gray" BorderThickness="1" Padding="5" SnapsToDevicePixels="True" Background="#02000000">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="50"/>
                                </Grid.ColumnDefinitions>
                                <ContentPresenter Margin="0 0 10 0" Content="{TemplateBinding Content}" VerticalAlignment="Center"/>
                                <Border x:Name="outterBd" Margin="-5" Padding="2" BorderBrush="Gray" BorderThickness="1 0 0 0" Grid.Column="1">
                                    <Border x:Name="innerBd" Background="LightGray" Grid.Column="1">
                                        <Border x:Name="slider"  Margin="5 -2 30 -2" Background="#FF4D4D4D"/>
                                    </Border>
                                </Border>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="bd" Property="BorderBrush" Value="{StaticResource ToolBarBackgroundBrush}"/>
                                <Setter TargetName="outterBd" Property="BorderBrush" Value="{StaticResource ToolBarBackgroundBrush}"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="true">
                                <Setter  Property="Margin" Value="30 -2 5 -2" TargetName="slider"/>
                                <Setter  Property="Background" Value="Gray" TargetName="innerBd"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="RadioButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <Border Margin="-1 0 0 0" SnapsToDevicePixels="True" x:Name="bd" BorderBrush="Gray" BorderThickness="1" Padding="5" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Background="#02000000">
                            <ContentPresenter  VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="bd" Property="BorderBrush" Value="{StaticResource ToolBarBackgroundBrush}"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="true">
                                <Setter TargetName="bd" Property="Background">
                                    <Setter.Value>
                                        <SolidColorBrush Color="LightGray"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

  

时间: 2024-08-05 22:15:50

WPF RadioButton & CheckBox Style的相关文章

WPF CHECKBOX STYLE

源自 http://www.wpfhelper.com/index.php/android-ui-for-wpf/23-modern-ui-for-wpf/android-ui-for-wpf/26-wpf-checkbox-style-inspired-by-android CheckBoxStyleXAMLWPF How create WPF CheckBox style and customize it. The CheckBox style is inspired by Android

背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

原文:背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch [源码下载] 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) ListBox RadioButton CheckBox ToggleSwitch 示例1.ListBox 的示例Controls/SelectionControl/ListBoxDemo.xaml <Page x:Class="Window

WPF 带CheckBox、图标的TreeView

WPF 带CheckBox.图标的TreeView 在WPF实际项目开发的时候,经常会用到带CheckBox的TreeView,虽然微软在WPF的TreeView中没有提供该功能,但是微软在WPF中提供强大的ItemTemplate模板功能和自定义样式,那我们可以自己写一个这样的控件供自己使用. 我自己写的这个比较简单. 首先写一个供TreeView使用的数据模型,并且实现INotifyPropertyChanged接口,用于向客户端(通常是执行绑定的客户端)发出某一属性值已更改的通知,当属性改

WPF中CheckBox三种状态打勾打叉

wpf的CheckBox支持三种状态,但是美中不足的是勾选中是是打勾,但是IsChecked为Fasle时,没显示打叉. 下面代码是自定义Style,打钩打叉: XAML: <Window x:Class="CheckBoxDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsof

Android高级UI ImageView ImageButton RadioButton CheckBox ProgressBar属性和用法总结

高级UI ImageView  ImageButton  RadioButton  CheckBox  ProgressBar 1.ImageView 图片组件 src 指定要加载的图片 缩放问题 1.按着图片原始比例(不失真) 2.不按着比例(失真) ScaleType 1.fitXY   强制让图片缩放以填充整个imageview 2.fitCenter  按着比例缩放以居中显示图片 3.fitEnd     按着比例缩放以局下部显示图片 4.fitStart   按着比例缩放以居上部显示图

android基本控件学习-----RadioButton&amp;CheckBox

RadioButton(单选框)和CheckBox(复选框)讲解: 一.基本用法和事件处理 (1)RadioButton单选框,就是只能选择其中的一个,我们在使用的时候需要将RadioButton放到RadioGroup中使用,同时我们还可以在RadioGroup中设置  orientation属性来控制单选框的方向. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi

WPF 自定义CheckBox样式

自定义CheckBox样式,mark一下,方便以后参考复用 设计介绍: 1.一般CheckBox模板太难看了,肯定要重写其中的模板 2.模板状态为未选中状态和选中状态,设置为默认未选中就好了. 默认状态,设置边框.透明度等 选中的话,我们可以设置√和背景. <Style x:Key="CheckBoxStyle" TargetType="{x:Type CheckBox}"> <Setter Property="SnapsToDevice

WPF 自定义Metro Style窗体

为了使WPF程序在不同版本的操作系统上保持一致的显示效果,我们需要重写WPF控件样式.这篇博客将展示如何创建一个Metro Style的WPF窗体. 首先先看一下最终窗体的效果图, 通过截图我们可以看出来这个窗体由两部分组成,顶部为最小化和关闭按钮,其他区域为窗体的显示区域.请看下面的具体实现代码, MetroWindow样式: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentat

WPF之样式——style

wpf这门编写winform程序的技术相比常规的winform技术有一个很显著的特点--炫! 怎么才能炫起来呢? 我们都知道常规的winform技术就是拖控件,总的来说想用常规的winform技术来实现很好看的界面很难. 但是wpf就可以实现起来很轻松. 有过web知识的童鞋很好理解,咱们看到的网站大部分都比winfrom好看的多,为啥? 因为里面所有的控件都是程序人员拿HTML编写的,编程人员可以自由的定义控件的样式.我们的WPF一样可以轻松的定义控件的样式. 下面我们一起来体验一下: 我们建