radiobutton文本不显示下划线(_)wpf

时间:2017-04-17 05:13:55

标签: c# wpf

  var item = new RadioButton { Content = "some_name"};
      item.Checked += radioButtonClick;
      item.Unchecked += radioButtonUnClick;

实际显示是某个名字。下划线缺失。要解决此问题,请在单选按钮上使用以下样式,但它有副作用。 Radiobutton图标不可见。

  <Style x:Key="{x:Type RadioButton}" TargetType="{x:Type RadioButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RadioButton}">
                    <Border Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        Padding="{TemplateBinding Padding}"
                        SnapsToDevicePixels="true">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                      RecognizesAccessKey="False"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

提前致谢

2 个答案:

答案 0 :(得分:0)

要在underscore中显示radiobutton,请使用以下代码。

<RadioButton ...... >
    <TextBlock Text="SELECT_ME" />
</RadioButton>

对于背后的代码

var item = new RadioButton { Content = new TextBlock { Text = "SELECT_ME" } };

答案 1 :(得分:0)

使用双下划线,因为单个下划线后跟一个字母被解释为访问键的定义。当您按下Alt键时,访问键会带有下划线。

如果要在标签/复选框/按钮/ ..上显示“ some_name”,则需要将内容指定为“ some__name”。

您可以在https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/how-to-create-a-control-that-has-an-access-key-and-text-wrapping

中了解有关访问键的更多信息。
相关问题