4

如何将单选按钮样式更改为 XAML 中的按钮样式?如果选中单选按钮,如何设置背景颜色?我想使用默认颜色(因为我使用不同的皮肤)。

4

2 回答 2

6

您需要为 RadioButton 定义 controltemplate 并在 controltemplate 中应用触发器。就像是。

<Style x:Key="ButtonRadioButtonStyle" TargetType="{x:Type RadioButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RadioButton}">
                    <Button Content="{TemplateBinding Content}"/>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasContent" Value="true">
                            <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
                            <Setter Property="Padding" Value="4,0,0,0"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

并像使用它一样。

<RadioButton Style="{DynamicResource ButtonRadioButtonStyle}">
            <Image Source="ImagePath\ABC.png"/>
        </RadioButton>

希望能帮助到你..

于 2012-12-11T10:54:47.863 回答
0

我经常使用这个选项

<RadioButton Height="23" Width="23" ToolTip="По левому краю" GroupName="TextAlignmentGroup"
                                                IsChecked="{Binding IsChecked}">
    <RadioButton.Template>
        <ControlTemplate TargetType="RadioButton">
            <Image Name="ImageName" Stretch="Fill"/>
            <ControlTemplate.Triggers>
                <Trigger Property="ToggleButton.IsChecked" Value="True">
                    <Setter TargetName="ImageName" Property="Image.Source">
                        <Setter.Value>
                            <BitmapImage UriSource="../../Resources/pressed.png"></BitmapImage>
                        </Setter.Value>
                    </Setter>
                </Trigger>
                <Trigger Property="ToggleButton.IsChecked" Value="False">
                    <Setter TargetName="ImageName" Property="Image.Source">
                        <Setter.Value>
                            <BitmapImage UriSource="../../Resources/image.png"></BitmapImage>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </RadioButton.Template>
</RadioButton>
于 2015-10-14T15:15:46.423 回答