WPF 仿IPhone滑块开关 样式 - CheckBox

原文: WPF 仿IPhone滑块开关 样式 - 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="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Cursor" Value="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="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="14"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                        <Storyboard x:Key="StoryboardIsCheckedOff">
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="CheckFlag">
                                <EasingDoubleKeyFrame KeyTime="0" Value="14"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="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="true">
                            <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
                            <Setter Property="Padding" Value="4,0,0,0"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="ForegroundPanel" Property="Background" Value="{DynamicResource Accent}" />
                            <Trigger.EnterActions>
                                <BeginStoryboard x:Name="BeginStoryboardCheckedTrue" Storyboard="{StaticResource StoryboardIsChecked}" />
                                <RemoveStoryboard BeginStoryboardName="BeginStoryboardCheckedFalse" />
                            </Trigger.EnterActions>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter TargetName="ForegroundPanel" Property="Background" Value="Gray" />
                            <Trigger.EnterActions>
                                <BeginStoryboard x:Name="BeginStoryboardCheckedFalse" Storyboard="{StaticResource StoryboardIsCheckedOff}" />
                                <RemoveStoryboard BeginStoryboardName="BeginStoryboardCheckedTrue" />
                            </Trigger.EnterActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

 

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Controls/CResource/SliderCheckBox.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
<StackPanel>
  <CheckBox Style="{DynamicResource SliderCheckBox}" Content="启动Windows时自动运行" 
      IsChecked="{Binding WindowsAutomatically, Mode=TwoWay}" Margin="0,0,0,15"/>
</StackPanel>

 

posted on 2019-05-01 09:26 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/10799155.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF是一种创建Windows应用程序的框架,它提供了许多可视化组件和工具,使得应用程序的创建变得更加容易和快捷。本次实例的项目是一个简单的点餐系统,它包含了以下几个主要模块: 1. 登录界面 用户需要输入用户名和密码才能成功登录,登录成功后,程序将跳转到订单界面。如果用户输入的用户名或密码不正确,则会提示错误信息。 2. 菜单界面 在菜单界面,用户可以查看所有可供选择的菜品列表,并可以选择需要点的菜品。每个菜品都可以显示它的描述、价格以及图片,用户可以在右侧的“购物车”中查看他们已经点的菜品以及总价。 3. 订单界面 订单界面用于显示用户已经点的菜品信息以及订单的总价。用户在确认购物车中的菜品信息无误后,可以点击“去结算”按钮,进入支付界面。 4. 支付界面 在支付界面,用户需要选择支付方式并输入对应的支付信息,如信用卡号、有效期和验证码等。支付成功后,程序将返回订单界面并提示用户支付成功。 通过使用WPF的鲁棒性、可扩展性和易用性,开发者可以在编写这样的小项目时得到很大的好处。开发者可以使用大量的分层和组件化方法,使他们的代码变得易于管理和扩展。此外,通过使用WPF的数据绑定和样式,开发者可以使程序的UI更加一致和响应式。总的来说,使用WPF编写点餐系统可以使开发者轻松地创建一个功能齐全、易于使用并具有良好用户体验的应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值