首页 > 其他分享 >WPF-‘_’在Lable中显示为文字的下划线不独立显示的问题。

WPF-‘_’在Lable中显示为文字的下划线不独立显示的问题。

时间:2023-01-05 17:13:52浏览次数:44  
标签:文字 Lable 显示 下划线 快捷键 WPF

一、原因:

   ‘_’在WPF中用于表示访问键。

二、对策:

  建立新样式,并关闭lable对快捷键的自动处理:RecognizesAccessKey="True"=》"False",如下:

        <!-- 不对下划线进行处理 -->
        <Style x:Key="LabelStyle1" TargetType="{x:Type Label}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Padding" Value="5"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Top"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Label}">
                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="False" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </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>

标签:文字,Lable,显示,下划线,快捷键,WPF
From: https://www.cnblogs.com/qq2806933146xiaobai/p/17028145.html

相关文章