WPF边距在windows XP/7上呈现方式不同

WPF边距在windows XP/7上呈现方式不同,wpf,.net-4.0,Wpf,.net 4.0,我已经尝试了位于的hack,但是它对这个问题没有影响,这里可能涉及到一些ScaleTransform,但是在两张图片中它的值是相同的。 有人知道为什么会有如此大的差异吗?有没有办法解决这个问题 以下是按钮的样式: <Style x:Key="activityButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Margin" Value="0,3,0,3" /> <Setter Pr

我已经尝试了位于的hack,但是它对这个问题没有影响,这里可能涉及到一些ScaleTransform,但是在两张图片中它的值是相同的。 有人知道为什么会有如此大的差异吗?有没有办法解决这个问题

以下是按钮的样式:

<Style x:Key="activityButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Margin" Value="0,3,0,3" />
    <Setter Property="Padding" Value="5" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="Background" Value="DarkGray" />
    <Setter Property="BorderThickness" Value="2" />
    <Setter Property="BorderBrush" Value="Black"/>
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.2"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Normal">
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="pushedBorder">
                                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="pushedBorder2">
                                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="pushedBorder3">
                                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="pushedBorder">
                                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="pushedBorder2">
                                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="pushedBorder3">
                                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled"/>
                            <VisualState x:Name="MouseOver"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" />
                    <Border x:Name="normalBorder" BorderThickness="{TemplateBinding BorderThickness}">
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#00000000" Offset="0.5"/>
                                <GradientStop Color="#19000000" Offset="0.51"/>
                            </LinearGradientBrush>
                        </Border.Background>
                    </Border>
                    <Border x:Name="pushedBorder4" BorderThickness="{TemplateBinding BorderThickness}">
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#00000000" Offset="0.5"/>
                                <GradientStop Color="#19000000" Offset="0.51"/>
                            </LinearGradientBrush>
                        </Border.Background>
                    </Border>
                    <Border x:Name="pushedBorder"  RenderTransformOrigin="0.5,0.5" Opacity="0" BorderBrush="#33000000" BorderThickness="3" CornerRadius="5"/>
                    <Border x:Name="pushedBorder2"  RenderTransformOrigin="0.5,0.5" Opacity="0" BorderBrush="#33000000" BorderThickness="4" CornerRadius="5"/>
                    <Border x:Name="pushedBorder3"  RenderTransformOrigin="0.5,0.5" Opacity="0" BorderBrush="#33000000" BorderThickness="5" CornerRadius="5"/>
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="5" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

虽然这不是一个好答案,但我不认为这是一个更糟糕的问题。WinXP将在2年内永远消失。我会将此作为一个bug归档,并在需要时返回。但如果您愿意,您可以作为另一种选择,在XAML或代码中使用条件编译指令。WinXP将在2年内永远消失。我会将此作为一个bug归档,并在需要时返回。但如果您愿意,您可以作为另一种选择,在XAML或代码中使用条件编译指令。