c# - 悬停时的 C# WPF 按钮未完全填充背景
问题描述
细节:
这是我的Login
Button 悬停时的输出:
目标:
我的目标是在悬停时在按钮内用蓝色填充少量的白色。
代码:
这是我的样式代码:
<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>
问题:
如何填充按钮边缘悬停的白色角落?
和
为什么要这样做?
解决方案
这只是曲线渲染问题,但我认为这不是问题。
我想出了以下解决方法:
<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>
推荐阅读
- sql - MyBatis:如何将默认参数传递给每个查询
- prometheus - PromQL 语句不起作用,而相同的记录规则起作用
- authentication - 如何在没有数据包管理器的情况下安装 PAM
- node.js - 如何解决 UnhandledPromiseRejectionWarning: MongooseError: Operation `menus.find()` buffering timed out after 10000ms 这个节点 js 中的问题?
- mysql - 如何在 Tuple Criteria MYSQL 中使用空值进行查询
- python - 找出字符串列表是否是人名
- sql - T-sql 替换 concat collate
- websocket - Swift5 - URLSessionWebSocketTask - 使用客户端 pong 响应来自服务器的 ping
- angular - 如何使用 ngx translate 翻译角材料小吃栏中的文本
- sql - BigQuery SQL:从日志表创建每日当前状态表