RadioButton改造成ImageButton,解决RadioButton没有选中状态

2017-07-18 11:29:42来源:CSDN作者:qq_23018459人点击



<!--RadioButton改造成ImageButton,解决RadioButton没有选中状态 add by yangxp@20170627-->
        <Style x:Key="RDOButton" TargetType="{x:Type RadioButton}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <ControlTemplate.Resources>
                            <Storyboard x:Key="Storyboard1" AutoReverse="False">
                                <!--AutoReverse表示动画是否正序运行后再反序运行-->
                                <!--BeginTime设置动画起始时间点 Duration表示动画运行周期时长 FillBehavlor设置一个值,该值指定动画在运行周期结束后的行为方式,默认为HoldEnd。简单来说就是保留值-->
                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="bd" >
                                    <EasingColorKeyFrame KeyTime="0" Value="White"/>
                                    <EasingColorKeyFrame KeyTime="0:0:0.3" Value="#FFAFAFAF"/>
                                </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                            <Storyboard x:Key="Storyboard2">
                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="bd">
                                    <EasingColorKeyFrame KeyTime="0" Value="#FFAFAFAF" />
                                    <EasingColorKeyFrame KeyTime="0:0:0.5" Value="#D3D3D3"/>
                                </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                           
                        </ControlTemplate.Resources>
                        <BulletDecorator Background="Transparent">
                            <Border x:Name="bd"  HorizontalAlignment="Center" Background="White" CornerRadius="5">
                                <Border.OpacityMask><!--透明掩码-->
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="Black" Offset="0"/>
                                        <GradientStop Color="White" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.OpacityMask>
                                <!--<Border x:Name="dd" Height="60" Width="50" >-->
                                    <StackPanel  x:Name="stack" HorizontalAlignment="Center" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"
                Margin="{TemplateBinding Padding}"  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                        <Image Width="35" Height="35" Margin="0,5" Source="/Images/zongfen.png"/>
                                        <TextBlock HorizontalAlignment="Center"><Run Text="测试"/></TextBlock>
                                    </StackPanel>
                                    <!--<Border.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform/>
                                        <SkewTransform/>
                                        <RotateTransform/>
                                        <TranslateTransform/>
                                    </TransformGroup>
                                </Border.RenderTransform>
                                </Border>-->
                                <!--<ContentPresenter Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
               HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>-->
                            </Border>
                        </BulletDecorator>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter TargetName="bd" Property="Background" Value="gray" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="false">
                                <Setter TargetName="bd" Property="Background" Value="{x:Null}" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="true">
                                <Trigger.EnterActions>
                                    <BeginStoryboard x:Name="Storyboard2_BeginStoryboard" Storyboard="{StaticResource Storyboard2}"/>
                                </Trigger.EnterActions>
                                <!--<Setter TargetName="bd" Property="Background" Value="#FF606060" />
                                <Setter Property="RenderTransform" TargetName="stack">
                                    <Setter.Value>
                                        <TransformGroup>
                                            <ScaleTransform ScaleX="1.05" ScaleY="1.05"/>
                                            <SkewTransform/>
                                            <RotateTransform/>
                                            <TranslateTransform/>
                                        </TransformGroup>
                                    </Setter.Value>
                                </Setter>-->
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
                                </MultiTrigger.EnterActions>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsMouseOver" Value="True"/>
                                    <Condition Property="IsChecked" Value="False"/>
                                </MultiTrigger.Conditions>
                                <Setter TargetName="bd" Property="Background" Value="Red" />
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

 <RadioButton Width="80" Height="70" Margin="2,5" VerticalAlignment="Center" Cursor="Hand" Name="yingyetingToolBarButton"  Click="YingyetingToolBarButton_Click" Style="{DynamicResource RDOButton}" SnapsToDevicePixels="True">
            </RadioButton>
            <RadioButton Width="80" Height="70" Margin="2,5" VerticalAlignment="Center" Cursor="Hand" Name="yingyetingToolBarButton1"  Click="YingyetingToolBarButton_Click" Style="{DynamicResource RDOButton}" SnapsToDevicePixels="True">
            </RadioButton>
            <RadioButton Width="80" Height="70" Margin="2,5" VerticalAlignment="Center" Cursor="Hand" Name="yingyetingToolBarButton2"  Click="YingyetingToolBarButton_Click" Style="{DynamicResource RDOButton}" SnapsToDevicePixels="True">
            </RadioButton>



最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台