5

当我在宽度为 120 的网格内使用进度条(IsIndertiminate=true)时,进度条动画看起来很奇怪。进度点似乎并排移动,它们之间没有任何适当的间距。此外,由于这个(宽度更小),点分别在开始和结束时移开/靠近的效果不太明显。

那么,当我以有限的宽度显示进度条时,如何使进度条看起来更好。我尝试自己搜索并更改progressBar的属性,但无法达到令人满意的状态。

编辑:在我的 grid.row 中,通过将我的 progressBar 的宽度设置为“自动”,我能够实现理想的间距/外观(它仍然不完美,但对我有用)。

4

2 回答 2

2

它只需要对该控件Style Template进行一些自定义,以对充当ProgressBar自身的形状进行一些调整。

目前我面前没有 WP7 ProgressBar 的默认样式模板,但是如果您在 Expression Blend 中打开您的项目,请右键单击它并选择“编辑模板 -> 编辑副本(或编辑原始文件)要公开样式模板,您会看到形状,我认为甚至驱动它的情节提要动画也准备好根据您的心愿进行编辑。

如果您提供默认模板的副本,我相信如果您自己没有得到它,我们可以很快为您提供解决方案。希望这可以帮助 :)

于 2013-04-03T20:20:38.067 回答
1

进度条默认样式,每个矩形都可以修改!

<Style x:Key="PerformanceProgressBarStyle1" TargetType="toolkit:PerformanceProgressBar">
        <Setter Property="IsIndeterminate" Value="False"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
        <Setter Property="Background" Value="{StaticResource PhoneAccentBrush}"/>
        <Setter Property="IsHitTestVisible" Value="False"/>
        <Setter Property="Padding" Value="{StaticResource PhoneHorizontalMargin}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="toolkit:PerformanceProgressBar">
                    <ProgressBar x:Name="EmbeddedProgressBar" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" IsIndeterminate="{TemplateBinding ActualIsIndeterminate}" Padding="{TemplateBinding Padding}">
                        <ProgressBar.Template>
                            <ControlTemplate TargetType="ProgressBar">
                                <toolkitPrimitives:RelativeAnimatingContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                                    <toolkitPrimitives:RelativeAnimatingContentControl.Resources>
                                        <ExponentialEase x:Key="ProgressBarEaseOut" EasingMode="EaseOut" Exponent="1"/>
                                        <ExponentialEase x:Key="ProgressBarEaseIn" EasingMode="EaseIn" Exponent="1"/>
                                    </toolkitPrimitives:RelativeAnimatingContentControl.Resources>
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="CommonStates">
                                            <VisualState x:Name="Determinate"/>
                                            <VisualState x:Name="Indeterminate">
                                                <Storyboard Duration="00:00:04.4" RepeatBehavior="Forever">
                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="IndeterminateRoot">
                                                        <DiscreteObjectKeyFrame KeyTime="0">
                                                            <DiscreteObjectKeyFrame.Value>
                                                                <Visibility>Visible</Visibility>
                                                            </DiscreteObjectKeyFrame.Value>
                                                        </DiscreteObjectKeyFrame>
                                                    </ObjectAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.0" Storyboard.TargetProperty="X" Storyboard.TargetName="R1TT">
                                                        <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseOut}" KeyTime="00:00:00.5" Value="33.1"/>
                                                        <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseIn}" KeyTime="00:00:02.5" Value="100.1"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="X" Storyboard.TargetName="R2TT">
                                                        <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseOut}" KeyTime="00:00:00.5" Value="33.1"/>
                                                        <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseIn}" KeyTime="00:00:02.5" Value="100.1"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="X" Storyboard.TargetName="R3TT">
                                                        <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseOut}" KeyTime="00:00:00.5" Value="33.1"/>
                                                        <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseIn}" KeyTime="00:00:02.5" Value="100.1"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.6" Storyboard.TargetProperty="X" Storyboard.TargetName="R4TT">
                                                        <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseOut}" KeyTime="00:00:00.5" Value="33.1"/>
                                                        <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseIn}" KeyTime="00:00:02.5" Value="100.1"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8" Storyboard.TargetProperty="X" Storyboard.TargetName="R5TT">
                                                        <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="0.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseOut}" KeyTime="00:00:00.5" Value="33.1"/>
                                                        <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="66.1"/>
                                                        <EasingDoubleKeyFrame EasingFunction="{StaticResource ProgressBarEaseIn}" KeyTime="00:00:02.5" Value="100.1"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R1">
                                                        <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                        <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R2">
                                                        <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                        <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R3">
                                                        <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                        <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.6" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R4">
                                                        <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                        <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R5">
                                                        <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                        <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                    <Border x:Name="IndeterminateRoot" Margin="{TemplateBinding Padding}">
                                        <Grid HorizontalAlignment="Left">
                                            <Rectangle x:Name="R1" CacheMode="BitmapCache" Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Opacity="0" Width="4">
                                                <Rectangle.RenderTransform>
                                                    <TranslateTransform x:Name="R1TT"/>
                                                </Rectangle.RenderTransform>
                                            </Rectangle>
                                            <Rectangle x:Name="R2" CacheMode="BitmapCache" Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Opacity="0" Width="4">
                                                <Rectangle.RenderTransform>
                                                    <TranslateTransform x:Name="R2TT"/>
                                                </Rectangle.RenderTransform>
                                            </Rectangle>
                                            <Rectangle x:Name="R3" CacheMode="BitmapCache" Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Opacity="0" Width="4">
                                                <Rectangle.RenderTransform>
                                                    <TranslateTransform x:Name="R3TT"/>
                                                </Rectangle.RenderTransform>
                                            </Rectangle>
                                            <Rectangle x:Name="R4" CacheMode="BitmapCache" Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Opacity="0" Width="4">
                                                <Rectangle.RenderTransform>
                                                    <TranslateTransform x:Name="R4TT"/>
                                                </Rectangle.RenderTransform>
                                            </Rectangle>
                                            <Rectangle x:Name="R5" CacheMode="BitmapCache" Fill="{TemplateBinding Foreground}" Height="4" IsHitTestVisible="False" Opacity="0" Width="4">
                                                <Rectangle.RenderTransform>
                                                    <TranslateTransform x:Name="R5TT"/>
                                                </Rectangle.RenderTransform>
                                            </Rectangle>
                                        </Grid>
                                    </Border>
                                </toolkitPrimitives:RelativeAnimatingContentControl>
                            </ControlTemplate>
                        </ProgressBar.Template>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="VisibilityStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.25" To="Normal"/>
                                    <VisualTransition GeneratedDuration="0:0:0.75" To="Hidden"/>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Hidden">
                                    <Storyboard>
                                        <DoubleAnimation To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="EmbeddedProgressBar"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </ProgressBar>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

例如,只需设置Widht = "2" Height = "2"可能就是您需要的!

   <Rectangle x:Name="R1" CacheMode="BitmapCache" Fill="{TemplateBinding Foreground}" Height="2" IsHitTestVisible="False" Opacity="0" Width="2">

您还可以使用任何形状,而不仅仅是矩形。不要忘记为您的 ProgresBar 分配此样式。

希望它的帮助。

于 2013-04-09T06:24:00.743 回答