WPF 自定义 RadioButton 2

<UserControl x:Class="CMApplication1.Views.CustomerRadioButtonView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"  Width="800" Height="600"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <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>
                        </ControlTemplate.Resources>
                        <BulletDecorator Background="Transparent">
                            <Canvas>
                                <ContentPresenter Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                <Path Name="image1" Stroke="Pink" StrokeThickness="5" Canvas.Left="30" Canvas.Top="30">
                                    <Path.Data>
                                        <PathGeometry>
                                            <PathFigure StartPoint="-15, 50">
                                                <ArcSegment Point="115, 50" Size="60, 60"></ArcSegment>
                                            </PathFigure>
                                        </PathGeometry>
                                    </Path.Data>
                                    <Path.RenderTransform>
                                        <RotateTransform CenterX="50" CenterY="50" />
                                    </Path.RenderTransform>
                                </Path>
                            </Canvas>
                        </BulletDecorator>
                        <ControlTemplate.Triggers>
                            <!--<EventTrigger  RoutedEvent="MouseEnter" >
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="image1" Storyboard.TargetProperty="RenderTransform.Angle" From="0" To="360" Duration="0:0:5" RepeatBehavior="Forever" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                            <EventTrigger  RoutedEvent="MouseLeave" >
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="image1" Storyboard.TargetProperty="RenderTransform.Angle" To="0" Duration="0:0:1" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>-->
                            <!--<Trigger Property="IsChecked" Value="false">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="image1" Storyboard.TargetProperty="RenderTransform.Angle" To="0" Duration="0:0:1" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            </Trigger>-->
                            <Trigger Property="IsChecked" Value="true">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="image1" Storyboard.TargetProperty="RenderTransform.Angle" From="0" To="360" Duration="0:0:6" RepeatBehavior="Forever" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                                <Trigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="image1" Storyboard.TargetProperty="RenderTransform.Angle" To="0" Duration="0:0:1" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.ExitActions>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <PathGeometry x:Key="path1">
            <PathFigure StartPoint="0, 64" IsClosed="True">
                <ArcSegment Point="128, 64" Size="64, 64"></ArcSegment>
                <ArcSegment Point="0, 64" Size="64, 64"></ArcSegment>
            </PathFigure>
        </PathGeometry>
    </UserControl.Resources>
    <Grid>
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal" Focusable="True">
            <StackPanel.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF727272" Offset="1" />
                    <GradientStop Color="#FFFFFF" Offset="0.654" />
                    <GradientStop Color="#FEFEFE" Offset="0" />
                    <GradientStop Color="#FFFFFFFB" Offset="0.994" />
                </LinearGradientBrush>
            </StackPanel.Background>
            <RadioButton Width="160" Height="160" Margin="2,5" Cursor="Hand" Name="yingyetingToolBarButton" VerticalAlignment="Top"
  Style="{DynamicResource RDOButton}" SnapsToDevicePixels="True">
                <Path Width="128" Height="128" Data="{StaticResource path1}" Margin="5">
                    <Path.Fill>
                        <ImageBrush  ImageSource="/images/printer.png" ></ImageBrush>
                    </Path.Fill>
                    <Path.RenderTransform>
                        <RotateTransform CenterX="50" CenterY="50" />
                    </Path.RenderTransform>
                </Path>
            </RadioButton>
            <RadioButton Width="160" Height="160" Margin="2,5" Cursor="Hand" Name="yingyechaxunToolBarButton" VerticalAlignment="Top"
  Style="{DynamicResource RDOButton}" SnapsToDevicePixels="True">
                <Path Width="128" Height="128" Data="{StaticResource path1}">
                    <Path.Fill>
                        <ImageBrush  ImageSource="/images/cc.jpg" ></ImageBrush>
                    </Path.Fill>
                    <Path.RenderTransform>
                        <RotateTransform CenterX="50" CenterY="50" />
                    </Path.RenderTransform>
                </Path>
            </RadioButton>
            <RadioButton Width="160" Height="160" Margin="2,5" Cursor="Hand" Name="jiaojiebanToolBarButton" VerticalAlignment="Top"
  Style="{DynamicResource RDOButton}" SnapsToDevicePixels="True">
                <Path Width="128" Height="128" Data="{StaticResource path1}">
                    <Path.Fill>
                        <ImageBrush ImageSource="/images/safari.png" ></ImageBrush>
                    </Path.Fill>
                </Path>
            </RadioButton>
        </StackPanel>
    </Grid>
</UserControl>

点击查看原图

知识共享许可协议
《WPF 自定义 RadioButton 2》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     170.64ms