WPF进度条边框厚度

时间:2018-07-25 20:07:09

标签: wpf

出于某种原因,当为自定义进度栏样式设置边框粗细时,边框不会保留相同的粗细吗?为什么会这样?理想情况下,边框的值为1。我只是将其设置为6,所以会夸大问题。

enter image description here

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:WpfApplication1.Themes">


    <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
        <Setter Property="Background" Value="{StaticResource GrayBrush5}" />
        <Setter Property="BorderBrush" Value="{StaticResource ControlBorderBrush}" />
        <Setter Property="BorderThickness" Value="6" />
        <Setter Property="Foreground" Value="{StaticResource AccentLightBrush}" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ProgressBar">
                    <Grid x:Name="Root">
                        <Border x:Name="PART_Track"
                                Margin="0"
                                SnapsToDevicePixels="True"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}" />
                        <Grid x:Name="ProgressBarRootGrid">
                            <Grid x:Name="IndeterminateRoot" Visibility="Collapsed">
                                <Rectangle x:Name="IndeterminateSolidFill"
                                           Margin="{TemplateBinding BorderThickness}"
                                           Fill="{TemplateBinding Background}"
                                           RenderTransformOrigin="0.5,0.5"
                                           StrokeThickness="0" />
                                <Rectangle x:Name="IndeterminateGradientFill"
                                           Margin="{TemplateBinding BorderThickness}"
                                           StrokeThickness="0">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush MappingMode="Absolute" SpreadMethod="Repeat" StartPoint="20,1" EndPoint="0,1">
                                            <LinearGradientBrush.Transform>
                                                <TransformGroup>
                                                    <TranslateTransform x:Name="xTransform" X="0" />
                                                    <SkewTransform AngleX="-30" />
                                                </TransformGroup>
                                            </LinearGradientBrush.Transform>
                                            <GradientStop Offset="0" Color="{StaticResource AccentLightColor}" />
                                            <GradientStop Offset="0.5" Color="{StaticResource AccentLightColor}" />
                                            <GradientStop Offset="0.5" Color="{StaticResource AccentDarkColor}" />
                                            <GradientStop Offset="1.0" Color="{StaticResource AccentDarkColor}" />
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Grid>
                            <Grid x:Name="DeterminateRoot" Margin="1">
                                <Border x:Name="PART_Indicator"
                                        Margin="0"
                                        HorizontalAlignment="Left"
                                        Background="{StaticResource AccentLightBrush}">
                                    <Rectangle x:Name="GradientFill" Visibility="Collapsed">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush MappingMode="Absolute" SpreadMethod="Repeat" StartPoint="20,1" EndPoint="0,1">
                                                <LinearGradientBrush.Transform>
                                                    <TransformGroup>
                                                        <TranslateTransform X="0" />
                                                        <SkewTransform AngleX="-30" />
                                                    </TransformGroup>
                                                </LinearGradientBrush.Transform>
                                                <GradientStop Offset="0" Color="{StaticResource AccentLightColor}" />
                                                <GradientStop Offset="0.5" Color="{StaticResource AccentLightColor}" />
                                                <GradientStop Offset="0.5" Color="{StaticResource AccentDarkColor}" />
                                                <GradientStop Offset="1.0" Color="{StaticResource AccentDarkColor}" />
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                </Border>
                            </Grid>
                        </Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Determinate" />
                                <VisualState x:Name="Indeterminate">
                                    <Storyboard RepeatBehavior="Forever">
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateRoot"
                                                                       Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Duration="00:00:00">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeterminateRoot"
                                                                       Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Duration="00:00:00">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="xTransform" Storyboard.TargetProperty="X">
                                            <SplineDoubleKeyFrame KeyTime="0" Value="0" />
                                            <SplineDoubleKeyFrame KeyTime="00:00:.35" Value="20" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Orientation" Value="Vertical">
                            <Setter TargetName="Root" Property="LayoutTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="-90" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsIndeterminate" Value="true">
                            <Setter TargetName="DeterminateRoot" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="IndeterminateRoot" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


</ResourceDictionary>

0 个答案:

没有答案