如何在RadioButton的顶部放置文本 [英] How to put text on top in RadioButton

查看:57
本文介绍了如何在RadioButton的顶部放置文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现附件中显示的效果,但没有成功.甚至有可能吗?我试图将文本框放在单选按钮内,并将其设置为水平和垂直内容匹配,但它并没有按照我的要求工作.欢迎任何建议.

I'm trying to achieve effect shown in attached file but without success. It is even possible? I was trying to put textbox inside the radiobutton and set to it horizontal and vertical content aligment but it's not working as I want. Any advices are welcome.

推荐答案

资源

<Window.Resources>
    <Style x:Key="RadioButton" TargetType="RadioButton">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RadioButton">
                    <StackPanel>
                        <TextBlock FontFamily="Segoe Ui Dark" HorizontalAlignment="Center"  Foreground="Black" Text="{TemplateBinding Content}" FontSize="12" FontWeight="SemiBold" Margin="0,0,0,2" />
                        <BulletDecorator Grid.Column="0" Background="Transparent" >
                            <BulletDecorator.Bullet>
                                <Grid Width="14" Height="14" >
                                    <Ellipse x:Name="Border" Fill="Transparent" StrokeThickness="1" Stroke="Black" />
                                    <Ellipse x:Name="CheckMark" Margin="4" Fill="Black"/>
                                </Grid>
                            </BulletDecorator.Bullet>
                        </BulletDecorator>
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="false">
                            <Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter TargetName="Border" Property="Fill" Value="LightGray" />
                            <Setter TargetName="Border" Property="Stroke" Value="Black" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Border" Property="Fill" Value="White" />
                            <Setter TargetName="Border" Property="Stroke" Value="Black" />
                            <Setter TargetName="Border" Property="StrokeThickness" Value="4" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>
</Window.Resources>

Xaml

<StackPanel Orientation="Horizontal">
    <RadioButton Content="1" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
    <RadioButton Content="2" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
    <RadioButton Content="3" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
    <RadioButton Content="4" Style="{StaticResource RadioButton}" Margin="5" ></RadioButton>
    <RadioButton Content="5" Style="{StaticResource RadioButton}" Margin="5"></RadioButton>
</StackPanel>

结果

这篇关于如何在RadioButton的顶部放置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆