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

发布于 2024-11-07 11:35:34 字数 1551 浏览 0 评论 0原文

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

在 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>

提前致谢,

约翰。

I want to change only the color inside the radio button when clicked. I mean the tiny dot inside the circle.

How in WPF can i do this?

I tried this code but it is saying the content is set more than once

<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>

Thanks in advance,

John.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕花眠 2024-11-14 11:35:34

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>

Move your ContentPresenter outside of your StackPanel. Actually, you don't appear to need the StackPanel at all:

<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>
勿忘初心 2024-11-14 11:35:34

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

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

This page might help you: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/35639a99-b2b2-4fe9-955d-775cb88ead43

It involves setting up a custom style for RadioButton.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文