Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 修改自定义样式的按钮';WPF XAML中的s边框_C#_Wpf_Xaml - Fatal编程技术网

C# 修改自定义样式的按钮';WPF XAML中的s边框

C# 修改自定义样式的按钮';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

我试图通过XAML代码实现,但没有效果

我有以下XAML代码:

App.xaml

<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属性。

谢谢,它成功了。由于某些原因,
产生,没有底线。我不得不将其更改为
,以获得所需的结果。