其他分享
首页 > 其他分享> > WPF个性选择框

WPF个性选择框

作者:互联网

样式代码:

<Style x:Key="CheckBoxStyle" TargetType="{x:Type CheckBox}">
            <Setter Property="Background" Value="#FF26405B"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CheckBox}">
                        <Grid Background="Transparent">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition  Width="auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Viewbox Width="{TemplateBinding Height}" Height="{TemplateBinding Height}">
                                <Grid>
                                    <Path Data="M1.5,16 C1.5,7.9918711 7.9918711,1.5 16,1.5 L69,1.5 C77.008129,1.5 83.5,7.9918711 83.5,16 L83.5,69 C83.5,77.008129 77.008129,83.5 69,83.5 L16,83.5 C7.9918711,83.5 1.5,77.008129 1.5,69 z"  Height="85"  Stretch="Fill" Stroke="{TemplateBinding Background}" StrokeThickness="3" Width="85"/>
                                    <Path x:Name="path" Data="M210,180 L239.5,199.5 269.5,154.5 234.5,184.5 z" Fill="{TemplateBinding Background}"  Height="46"  Stretch="Fill"  Width="60.5" RenderTransformOrigin="0.5,0.5">
                                        <Path.RenderTransform>
                                            <TransformGroup>
                                                <ScaleTransform ScaleX="0" ScaleY="0"/>
                                                <SkewTransform/>
                                                <RotateTransform/>
                                                <TranslateTransform/>
                                            </TransformGroup>
                                        </Path.RenderTransform>
                                    </Path>
                                </Grid>
                            </Viewbox>
                            <ContentPresenter Grid.Column="1" Margin="5 0 0 0" HorizontalAlignment="Left" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Trigger.ExitActions>
                                    <BeginStoryboard >
                                        <Storyboard >
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="path">
                                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="path">
                                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.ExitActions>
                                <Trigger.EnterActions>
                                    <BeginStoryboard >
                                        <Storyboard >
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="path">
                                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="path">
                                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

效果:

标签:效果,样式,代码,选择,WPF,个性
来源: https://www.cnblogs.com/qq2806933146xiaobai/p/16301054.html