C# 从按钮WPF移除阴影

C# 从按钮WPF移除阴影,c#,wpf,button,styles,shadow,C#,Wpf,Button,Styles,Shadow,我已在WPF应用程序中为按钮创建了样式: <Style x:Key="buttonStyle" TargetType="Button"> <Setter Property="Border.BorderBrush" Value="Black" /> <Setter Property="Border.BorderThickness" Value="1" /> <Setter Property="Border.Background" V

我已在WPF应用程序中为按钮创建了样式:

<Style x:Key="buttonStyle" TargetType="Button">
    <Setter Property="Border.BorderBrush" Value="Black" />
    <Setter Property="Border.BorderThickness" Value="1" />
    <Setter Property="Border.Background" Value="White" />
    <Setter Property="Height" Value="25" />
    <Setter Property="Width" Value="100" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border
                    Width="{TemplateBinding Width}"
                    Height="{TemplateBinding Height}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                    <ContentPresenter
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Content="{TemplateBinding Content}"
                        ContentTemplate="{TemplateBinding ContentTemplate}" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="Red" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

然后我将此样式设置为按钮控制:

<Button Style="{StaticResource buttonStyle}" Grid.Row="1" Grid.Column="1" Content="Press"/>


当我运行我的应用程序时,我看到按钮下方和右侧有灰色阴影。此外,当我在VisualStudio视图中查看时,我看不到阴影。如何删除此效果?有人有想法或完全不同的方法吗?

你确定你看到的实际上是一个影子吗?它可能只是一条模糊的边缘。WPF的布局系统基于与设备无关的像素,因此元素的边缘可能位于两个设备像素之间,在这种情况下,它可能会显得模糊


通过在WPF 4.0及更高版本中的父元素上设置
UseLayoutRounding=“True”
,可以强制设备像素捕捉;在早期版本中,您可以尝试
SnapsToDevicePixels=“True”

我刚刚将您的示例粘贴到一个空的WPF项目中,我没有看到任何灰色阴影。只是一个按钮,当你在上面悬停时会变成红色。可能您有一些其他样式无意中应用于按钮?除非您显式设置
效果
属性,否则WPF中的控件上不能有阴影。。。在这个代码示例中没有这个。如果您在代码中搜索
效果
,您可能会找到添加它的位置?不,我没有任何其他样式和效果。运行应用程序时,您可以看到这种效果。运行应用程序后,请比较按钮的边缘。正如你所看到的,其中一个几乎没有影子。我已经在空白项目中粘贴了这段代码,但仍然存在问题@Sheridan我正在Windows 8.1中运行应用程序。正如@Grantwiney告诉您的,您的问题阴影不在示例代码中。我可以在Windows 8.1上确认这一点。在您提供一些实际演示您的问题的代码之前,我已经投票结束这个问题,因为在这个阶段我们无法提供任何帮助。如果你用一个有效的代码示例编辑你的问题,我当然很乐意取消我的投票。你确定这是一个阴影而不是模糊的边缘吗?WPF布局基于与设备无关的像素,因此元素的边缘可能位于两个设备像素之间,在这种情况下,它可能看起来模糊。你能发布一个截图给我们看看它的样子吗?