• WPF-19:分享一个样式(左右滑动选中的checbox)


    首先看下效果。
    选中:

    不选中

    样式:

    <Style x:Key="CheckStyle" TargetType="{x:Type CheckBox}">
                    <Setter Property="Height" Value="18"/>
                    <Setter Property="Foreground" Value="White"/>
                    <Setter Property="FontWeight" Value="Bold"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type CheckBox}">
                                <Border x:Name="ForegroundPanel" CornerRadius="2" BorderBrush="Black" BorderThickness="1" Padding="0">
                                    <DockPanel>
                                        <TextBlock x:Name="Content" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2,0" />
                                        <Border x:Name="CheckFlag" HorizontalAlignment="Right" VerticalAlignment="Center" CornerRadius="2" BorderThickness="0" Width="18" Height="16"/>
                                    </DockPanel>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsChecked" Value="True">
                                        <Setter TargetName="Content" Property="Text" Value="是"/>
                                        <Setter TargetName="ForegroundPanel" Property="Background">
                                            <Setter.Value>
                                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                    <GradientStop Color="Gray" Offset="0.0"/>
                                                    <GradientStop Color="Blue" Offset="0.5"/>
                                                    <GradientStop Color="Gray" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter TargetName="CheckFlag" Property="Background">
                                            <Setter.Value>
                                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                    <GradientStop Color="WhiteSmoke" Offset="0.0"/>
                                                    <GradientStop Color="Green" Offset="0.5"/>
                                                    <GradientStop Color="WhiteSmoke" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter TargetName="Content" Property="DockPanel.Dock" Value="Left"/>
                                        <Setter TargetName="CheckFlag" Property="DockPanel.Dock" Value="Right"/>
                                    </Trigger>
                                    <Trigger Property="IsChecked" Value="False">
                                        <Setter TargetName="Content" Property="Text" Value="否"/>
                                        <Setter TargetName="ForegroundPanel" Property="Background">
                                            <Setter.Value>
                                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                    <GradientStop Color="Gray" Offset="0.0"/>
                                                    <GradientStop Color="Silver" Offset="0.5"/>
                                                    <GradientStop Color="Gray" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter TargetName="CheckFlag" Property="Background">
                                            <Setter.Value>
                                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                    <GradientStop Color="WhiteSmoke" Offset="0.0"/>
                                                    <GradientStop Color="Silver" Offset="0.5"/>
                                                    <GradientStop Color="WhiteSmoke" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter TargetName="Content" Property="DockPanel.Dock" Value="Right"/>
                                        <Setter TargetName="CheckFlag" Property="DockPanel.Dock" Value="Left"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

    在程序中的使用:

     <CheckBox Content="CheckBox" Height="34" HorizontalAlignment="Left" Margin="140,162,0,0" Name="checkBox1" VerticalAlignment="Top" Width="151" 
                      Style="{StaticResource CheckStyle}"/>

    代码下载: http://download.csdn.net/detail/yysyangyangyangshan/5647793


  • 相关阅读:
    Python高阶函数
    获取checkbox勾选的id
    按照勾选 删除表格的行<tr>
    mysql where和having的区别
    条件查询 日期区间
    根据状态隐藏按钮
    单击列表行前边的checkbox被选中,再单击,取消选中
    重置按钮
    TypeError: $(…).tooltip is not a function
    list的add()方法与addAll()方法简介
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3155314.html
Copyright © 2020-2023  润新知