0

如何设置 ProgressBar 的样式以使用老式的刻度线?有这个问题,但它是WinForms。

在此处输入图像描述

4

1 回答 1

1

我希望下面的风格是一个很好的起点。我留给您设置绿色刻度的样式(VisualBrush 的第一个矩形的背景)。

    <Style TargetType="{x:Type ProgressBar}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Determinate" />
                                <VisualState x:Name="Indeterminate">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="00:00:00"
                                                                       Storyboard.TargetName="PART_Indicator"
                                                                       Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <SolidColorBrush>Transparent</SolidColorBrush>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_GlowRect" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="0" Value="#00FFFFFF" />
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_GlowRect" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
                                            <EasingColorKeyFrame KeyTime="0" Value="#00FFFFFF" />
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="PART_Track"
                                Background="White"
                                BorderBrush="#FFDEDEDE"
                                BorderThickness="2"
                                ClipToBounds="True"
                                CornerRadius="3">
                            <Border x:Name="PART_Indicator"
                                    Margin="4"
                                    HorizontalAlignment="Left"
                                    BorderThickness="0"
                                    CornerRadius="0">
                                <Border.Background>
                                    <VisualBrush Stretch="None"
                                                 TileMode="Tile"
                                                 Viewbox="0,0,1.,1"
                                                 ViewboxUnits="RelativeToBoundingBox"
                                                 Viewport="0,0,30,30"
                                                 ViewportUnits="Absolute">
                                        <VisualBrush.Visual>
                                            <StackPanel Orientation="Horizontal">
                                                <Rectangle Width="30"
                                                           Height="30"
                                                           Fill="#FF23FF00" />
                                                <Rectangle Width="10"
                                                           Height="30"
                                                           Fill="Transparent" />
                                            </StackPanel>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </Border.Background>

                                <Grid x:Name="Animation" ClipToBounds="True">
                                    <Border x:Name="PART_GlowRect"
                                            Width="100"
                                            Margin="-100,0,0,0"
                                            HorizontalAlignment="Left"
                                            VerticalAlignment="Stretch"
                                            CornerRadius="0">
                                        <Border.Background>
                                            <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                                <GradientStop Offset="0" Color="#00E8DF2E" />
                                                <GradientStop Offset="0.4" Color="#FF38E41D" />
                                                <GradientStop Offset="0.6" Color="#FF38E41D" />
                                                <GradientStop Offset="1" Color="#00E8DF2E" />
                                            </LinearGradientBrush>
                                        </Border.Background>
                                    </Border>
                                </Grid>
                            </Border>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
于 2015-03-21T08:19:58.100 回答