WPF Margin在Windows XP / 7上的呈现方式不同

时间:2011-12-02 09:47:17

标签: wpf .net-4.0

Render diff

我已经尝试过位于http://arbel.net/2006/11/03/forcing-wpf-to-use-a-specific-windows-theme/的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>

0 个答案:

没有答案