C# 修改自定义样式的按钮';WPF XAML中的s边框
我试图通过XAML代码实现,但没有效果 我有以下XAML代码: App.xamlC# 修改自定义样式的按钮';WPF XAML中的s边框,c#,wpf,xaml,C#,Wpf,Xaml,我试图通过XAML代码实现,但没有效果 我有以下XAML代码: App.xaml <Style x:Key="ButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Background" Value="Black"/> <Setter Property="Template"> <Setter.Value> <Contro
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Path Fill="{TemplateBinding Background}"
Data="M 0,22.5 22.5,0 27.5,5 10,22.5 27.5,40 22.5,45"/>
<Border x:Name="border"
BorderThickness="2"
BorderBrush="Red"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
并像这样使用它:
<Button Style="{StaticResource ButtonStyle}" Height="100" Width="100"/>
它给了我,但我希望红色边框在按钮内
我试着加上这个
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="2"/>
而不是创建网格,但现在边界不显示
我想我可以创建另一条作为边界的路径,但有更简单的方法吗
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Path Fill="{TemplateBinding Background}" Stroke="Red" StrokeThickness="3"
Data="M 0,22.5 22.5,0 27.5,5 10,22.5 27.5,40 22.5,45"/>
<Border x:Name="border"
BorderThickness="2"
BorderBrush="Red"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
尝试使用Stroke和StrokeThickness属性。谢谢,它成功了。由于某些原因,
产生,没有底线。我不得不将其更改为
,以获得所需的结果。