【问题标题】:C# How to make UWP XAML button not show border on hoverC#如何使UWP XAML按钮在悬停时不显示边框
【发布时间】:2019-06-23 23:58:25
【问题描述】:

这是我的按钮:

    <Button
        x:Name="buttonClear"
        Width="74"
        Height="52"
        Margin="3,175,0,0"
        Padding="8,1,8,5"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        Content="C"
        FontSize="24"
        FontWeight="Normal"
        FocusVisualPrimaryBrush="Transparent"
        FocusVisualSecondaryThickness="0"
        Style="{ThemeResource ButtonRevealStyle}"
        Click="ButtonClear_Click" />

如你所见,我添加了:

FocusVisualPrimaryBrush="Transparent"
FocusVisualSecondaryThickness="0"

我认为它会消除将鼠标指针悬停在按钮上时显示的灰色边框。但它没有用。

我还尝试将以下内容添加到 App.xaml:

<Application.Resources>
    <SolidColorBrush x:Key="ButtonBackgroundPointerOver">Transparent</SolidColorBrush>
</Application.Resources>

还是没有结果。我必须在其他地方引用密钥吗?

【问题讨论】:

    标签: c# xaml uwp


    【解决方案1】:

    最简单的解决办法就是用BorderThickness="0"隐藏边框

    或者,您可以按照 visc 的建议编辑按钮的完整样式。

    【讨论】:

    • @EsAMe,如果回复有帮助请标记为答案。
    【解决方案2】:

    您需要修改Button 的完整样式。完整的Button 样式具有悬停的VisualState 定义。只需修改或删除它的情节提要。

    查看此链接,您将找到完整的默认按钮样式定义。 https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/button-styles-and-templates

    我个人创建了一个资源字典文件,并导入到我的所有页面中,当我定义新按钮时,我将 BasedOn 设置为资源字典中修改后的按钮样式。

    【讨论】:

    • 我真的没有那么先进,所以我不知道如何正确地做到这一点。
    猜你喜欢
    • 2019-04-05
    • 2018-04-12
    • 2016-12-26
    • 2021-05-19
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多