WPF单选按钮图标更改(圆圈本身)

时间:2019-02-12 14:09:56

标签: wpf radio-button

我希望有一组单选按钮,用于将未选择和选择的模式的圆圈更改为我设计的圆圈图标。

有可能在WPF中做到吗? 预先感谢

2 个答案:

答案 0 :(得分:1)

是的,当然可以。您可以覆盖默认的 ControlTemplate 并为自己的单选按钮创建样式。 Here是一个示例,您也可以使用Style Snooper来查看WPF内置的单选按钮样式(一大段XAML代码:))

答案 1 :(得分:1)

创建样式并覆盖RadioButtons的默认模板。像这样:

<Window.Resources>
    <Style TargetType="RadioButton">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RadioButton}">
                    <BulletDecorator Background="Transparent">
                        <BulletDecorator.Bullet>
                            <Grid Width="13" Height="13">
                                <Ellipse x:Name="Border" StrokeThickness="2">
                                    <Ellipse.Stroke>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="Green" Offset="0" />
                                            <GradientStop Color="Pink" Offset="1" />
                                        </LinearGradientBrush>
                                    </Ellipse.Stroke>
                                    <Ellipse.Fill>
                                        <LinearGradientBrush StartPoint="0,0"
                                   EndPoint="0,1">
                                            <LinearGradientBrush.GradientStops>
                                                <GradientStopCollection>
                                                    <GradientStop Color="Orange" />
                                                    <GradientStop Color="Red"
                                  Offset="1.0" />
                                                </GradientStopCollection>
                                            </LinearGradientBrush.GradientStops>
                                        </LinearGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Ellipse x:Name="CheckMark"
                   Margin="4"
                   Visibility="Collapsed">
                                    <Ellipse.Fill>
                                        <SolidColorBrush Color="Purple" />
                                    </Ellipse.Fill>
                                </Ellipse>
                            </Grid>
                        </BulletDecorator.Bullet>
                      <ContentPresenter Margin="4,0,0,0"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Left"
                        RecognizesAccessKey="True" />
                    </BulletDecorator>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>