首页 > 解决方案 > 悬停时的 C# WPF 按钮未完全填充背景

问题描述

细节:

这是我的LoginButton 悬停时的输出:

在此处输入图像描述

目标:

我的目标是在悬停时在按钮内用蓝色填充少量的白色。

代码:

这是我的样式代码:

<Style TargetType="{x:Type Button}" x:Key="login_Btn">
<Setter Property="Foreground" Value="#004263"/>
<Setter Property="FontFamily" Value="Helvetica"/>
<Setter Property="FontWeight" Value="Light"/>


<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
            <Border Background="{TemplateBinding Background}" CornerRadius="20"
                                                              BorderThickness="2"
                                                              BorderBrush="#004263">

                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>

            </Border>
        </ControlTemplate>
    </Setter.Value>
</Setter>

<Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="#004263"/>
            <Setter Property="Foreground" Value="White"/>
        </Trigger>
</Style.Triggers>

</Style>

问题:

如何填充按钮边缘悬停的白色角落?

为什么要这样做?

标签: c#wpf

解决方案


这只是曲线渲染问题,但我认为这不是问题。

我想出了以下解决方法:

<ControlTemplate TargetType="{x:Type Button}">
    <Grid>
        <Border Background="{TemplateBinding Background}" CornerRadius="20" BorderThickness="0"/>
        <Border CornerRadius="20" BorderThickness="2" BorderBrush="#004263">
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Border>
    </Grid>
</ControlTemplate>

推荐阅读