如何更改单选按钮内圆圈的颜色

时间:2011-05-15 08:06:29

标签: wpf .net-3.5

单击时,我只想更改单选按钮内的颜色。我的意思是圆圈内的小点。

如何在WPF中执行此操作?

我试过这段代码,但是说内容设置不止一次

<BulletDecorator Background="Transparent">
    <BulletDecorator.Bullet>
        <StackPanel Orientation="Horizontal">
            <Grid Width="40" Height="40">
                <Ellipse Name="MainEllipse" Width="40" Height="40">
                    <Ellipse.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFC8C8C8" Offset="0" />
                            <GradientStop Color="#FFF7F7F7" Offset="0.991" />
                        </LinearGradientBrush>
                    </Ellipse.Fill>
                </Ellipse>

                <Ellipse Margin="10,10,10,10"
                         Fill="#C0C0C0"
                         Width="Auto"
                         Height="Auto" />

                <Ellipse x:Name="Selected"
                         Margin="10,10,10,10"
                         Width="Auto"
                         Height="Auto">

                    <Ellipse.Fill>
                        <SolidColorBrush Color="Navy" />
                    </Ellipse.Fill> 
                </Ellipse>
            </Grid>
            <ContentPresenter Margin="5,0,0,0" VerticalAlignment="Center" />
        </StackPanel>
    </BulletDecorator.Bullet>
</BulletDecorator>

提前致谢,

约翰。

2 个答案:

答案 0 :(得分:1)

ContentPresenter移到StackPanel之外。实际上,您似乎根本不需要StackPanel

<BulletDecorator Background="Transparent">
    <BulletDecorator.Bullet>
        <Grid Width="40" Height="40">
            <Ellipse Name="MainEllipse" Width="40" Height="40">
                <Ellipse.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFC8C8C8" Offset="0" />
                        <GradientStop Color="#FFF7F7F7" Offset="0.991" />
                    </LinearGradientBrush>
                </Ellipse.Fill>
            </Ellipse>

            <Ellipse Margin="10,10,10,10"
                Fill="#C0C0C0"
                Width="Auto"
                Height="Auto" />

            <Ellipse x:Name="Selected"
                Margin="10,10,10,10"
                Width="Auto"
                Height="Auto">
                <Ellipse.Fill>
                    <SolidColorBrush Color="Navy" />
                </Ellipse.Fill> 
            </Ellipse>
        </Grid>
    </BulletDecorator.Bullet>
    <ContentPresenter Margin="5,0,0,0" VerticalAlignment="Center" />
</BulletDecorator>

答案 1 :(得分:0)

此页面可能会对您有所帮助:http://social.msdn.microsoft.com/forums/en-US/wpf/thread/35639a99-b2b2-4fe9-955d-775cb88ead43

它涉及为RadioButton设置自定义样式。