首页 > 代码库 > wpf iphone滑块样式CheckBox
wpf iphone滑块样式CheckBox
原文链接http://www.ilisen.net/iphone-slider-switch-style-checkbox.html
<!--CheckBox样式--> <Style x:Key="CheckRadioFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle Margin="14,0,0,0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="SliderCheckBox" TargetType="{x:Type CheckBox}"> <Setter Property="Foreground" Value="http://www.mamicode.com/{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="BorderThickness" Value="http://www.mamicode.com/1"/> <Setter Property="Cursor" Value="http://www.mamicode.com/Hand" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type CheckBox}"> <ControlTemplate.Resources> <Storyboard x:Key="StoryboardIsChecked"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="CheckFlag"> <EasingDoubleKeyFrame KeyTime="0" Value="http://www.mamicode.com/0"/> <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="http://www.mamicode.com/14"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="StoryboardIsCheckedOff"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="CheckFlag"> <EasingDoubleKeyFrame KeyTime="0" Value="http://www.mamicode.com/14"/> <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="http://www.mamicode.com/0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources> <BulletDecorator Background="Transparent" SnapsToDevicePixels="true"> <BulletDecorator.Bullet> <Border x:Name="ForegroundPanel" BorderThickness="1" Width="35" Height="20" CornerRadius="10"> <Canvas> <Border Background="White" x:Name="CheckFlag" CornerRadius="10" VerticalAlignment="Center" BorderThickness="1" Width="19" Height="18" RenderTransformOrigin="0.5,0.5"> <Border.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform/> <TranslateTransform/> </TransformGroup> </Border.RenderTransform> <Border.Effect> <DropShadowEffect ShadowDepth="1" Direction="180" /> </Border.Effect> </Border> </Canvas> </Border> </BulletDecorator.Bullet> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/> </BulletDecorator> <ControlTemplate.Triggers> <Trigger Property="HasContent" Value="http://www.mamicode.com/true"> <Setter Property="FocusVisualStyle" Value="http://www.mamicode.com/{StaticResource CheckRadioFocusVisual}"/> <Setter Property="Padding" Value="http://www.mamicode.com/4,0,0,0"/> </Trigger> <Trigger Property="IsEnabled" Value="http://www.mamicode.com/false"> <Setter Property="Foreground" Value="http://www.mamicode.com/{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> <Trigger Property="IsChecked" Value="http://www.mamicode.com/True"> <Setter TargetName="ForegroundPanel" Property="Background" Value="http://www.mamicode.com/Green" /> <Trigger.EnterActions> <BeginStoryboard x:Name="BeginStoryboardCheckedTrue" Storyboard="{StaticResource StoryboardIsChecked}" /> <RemoveStoryboard BeginStoryboardName="BeginStoryboardCheckedFalse" /> </Trigger.EnterActions> </Trigger> <Trigger Property="IsChecked" Value="http://www.mamicode.com/False"> <Setter TargetName="ForegroundPanel" Property="Background" Value="http://www.mamicode.com/Gray" /> <Trigger.EnterActions> <BeginStoryboard x:Name="BeginStoryboardCheckedFalse" Storyboard="{StaticResource StoryboardIsCheckedOff}" /> <RemoveStoryboard BeginStoryboardName="BeginStoryboardCheckedTrue" /> </Trigger.EnterActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 使用: 1 <CheckBox Style="{DynamicResource SliderCheckBox}" Content="启动Windows时自动运行" IsChecked="{Binding WindowsAutomatically, Mode=TwoWay}" Margin="0,0,0,15"/>
http://www.ilisen.net/wp-content/uploads/2013/12/20131212144733.png
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。