在WPF中,要禁用按钮的边框,可以通过修改按钮的模板来实现。以下是一个简单的示例,演示了如何禁用按钮的边框:
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}"
BorderThickness="0"
BorderBrush="Transparent">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
TextElement.Foreground="{TemplateBinding Foreground}" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
在这个示例中,我们通过设置BorderThickness
和BorderBrush
属性为0和透明,来禁用了按钮的边框。
完整的代码示例如下:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button Content="Click me"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}"
BorderThickness="0"
BorderBrush="Transparent">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
TextElement.Foreground="{TemplateBinding Foreground}" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Window>
这样,当用户单击按钮时,就不会显示边框。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云