如何在XAML中更改已检查的单选按钮的边框?

时间:2014-05-03 07:00:07

标签: wpf xaml

当我们将其中任何一个检查为true时,我有一组单选按钮我想将其边框刷更改为“Aqua”,同时返回检查为假边框刷为黑色 我想在vb.net和C#中都不会在XAML中这样做...

    <StackPanel Margin="10">
        <RadioButton GroupName="OS" Content="Win. XP" IsChecked="True" BorderBrush="Aqua" BorderThickness="50"/>
        <RadioButton GroupName="OS" Content="Win. 7"/>
        <RadioButton GroupName="OS" Content="Win. 8"/>
        <StackPanel Margin="10"/>
        <RadioButton GroupName="Office" Content="Office Xp"/>
        <RadioButton GroupName="Office" Content="Microsoft Office 2007"/>
        <RadioButton GroupName="Office" Content="Microsoft Office 2003"/>
    </StackPanel>

Thanx In Advance ..

1 个答案:

答案 0 :(得分:2)

您可以将触发器用于此目的

<StackPanel Margin="10">
    <StackPanel.Resources>
        <Style TargetType="RadioButton">
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="BorderBrush" Value="Aqua"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </StackPanel.Resources>
    <RadioButton GroupName="OS" Content="Win. XP" IsChecked="True"/>
    <RadioButton GroupName="OS" Content="Win. 7"/>
    <RadioButton GroupName="OS" Content="Win. 8"/>
    <StackPanel Margin="10"/>
    <RadioButton GroupName="Office" Content="Office Xp"/>
    <RadioButton GroupName="Office" Content="Microsoft Office 2007"/>
    <RadioButton GroupName="Office" Content="Microsoft Office 2003"/>
</StackPanel>