【问题标题】:Progressbar dots spacing issue in Windows PhoneWindows Phone 中的进度条点间距问题
【发布时间】:2013-03-20 14:26:53
【问题描述】:

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

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

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

【问题讨论】:

    标签: silverlight windows-phone-7 xaml progress-bar


    【解决方案1】:

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

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

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

    【讨论】:

    • 这是我的问题。我应该编辑什么控件/属性。 gist.github.com/ua741/507cf05f73e394d99898#file-gistfile1-xml
    • @op_amp 我忘记了他们为 WP7 使用的资源字典文件,但是快速搜索 TargetType="ProgressBar" 的解决方案应该很快就能找到。或者你可以像上面提到的那样用 Expression Blend 快速制作一个副本。
    【解决方案2】:

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

    <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 分配此样式。

    希望有帮助。

    【讨论】:

    • 退后一步,我看到了支持 Mono 项目的 ASCII 艺术;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多