8

WPF 如何修改button圆角(经典)

 3 years ago
source link: http://developer.51cto.com/art/202102/645102.htm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

本人想设置Button为圆角,奈何搜索百度,找到的全是坑爹答案,现总结如下:

1. 需要添加button 的template.

2. 设置border的时候,必须要设置background, 否则会提示content 被多次使用。

#FFDDDDDD

我们只需要在XAML中给他添加几行代码就可以做成圆角形状。

属性解析:

BorderThickness:边框的大小

BorderBrush:边框的颜色

CornerRadius:圆角的大小

Background:背景颜色"{TemplateBinding Background}":这个就是使用上面

:文字垂直居中对齐

加个渐变色

如图:

图片

项目实例:

把样式和空间模板放到资源中,然后去引用

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:local="clr-namespace:WpfApp18"

mc:Ignorable="d"

Title="MainWindow" Height="450" Width="800">

鼠标放到按钮上以后按钮呈现蓝色

图片


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK