【问题标题】:A thicker ProgressBar in WP7, how?WP7 中的一个更粗的 ProgressBar,怎么样?
【发布时间】:2011-05-01 09:50:39
【问题描述】:

我正在制作一个具有计数器和表示剩余时间的进度条的应用程序,因此如果计数器达到其 50%,则进度条值为 50。到目前为止一切顺利,我制作了计数器总计的进度条动画并继续。

我的问题是:如何使进度条变粗?这条线本身太小了,我的应用程序的“主要吸引力”是进度条,我想让它更大。我必须制作模板并使用另一个控件吗? (就像在视觉上使用矩形一样)。我尝试将进度条更改为矩形,但我不知道如何填充矩形的 60%(例如)。

有什么想法吗?谢谢!

【问题讨论】:

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


    【解决方案1】:

    这可以在进度条的样式中完成。

    在默认进度条的样式中,你需要

    • 为 ProgressBar 样式添加高度, 说 30。
    • 增加两个矩形的高度 ProgressBarTrack 和 ProgressBarIndicator 为 24。它们是 在 ProgressBar 的 ControlTemplate 中。
    • 增加高度 Horizo​​ntalThumb 到 24。它在里面 PhoneProgressBarSliderStyle。
    • 在电话中ProgressBarSliderThumb ControlTemplate,同时增加 矩形的宽度和高度为 24。

    这是所有样式以防万一。:)

        <ControlTemplate x:Key="PhoneProgressBarSliderThumb" TargetType="Thumb">
            <Rectangle Fill="{TemplateBinding Foreground}" Height="24" IsHitTestVisible="False" Width="24"/>
        </ControlTemplate>
        <Style x:Key="PhoneProgressBarSliderStyle" TargetType="Slider">
            <Setter Property="Maximum" Value="3000"/>
            <Setter Property="Minimum" Value="0"/>
            <Setter Property="Value" Value="0"/>
            <Setter Property="Opacity" Value="0"/>
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Slider">
                        <Grid IsHitTestVisible="False">
                            <Grid x:Name="HorizontalTemplate">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <RepeatButton x:Name="HorizontalTrackLargeChangeDecreaseRepeatButton" Grid.Column="0" Height="0" Template="{x:Null}"/>
                                <Thumb x:Name="HorizontalThumb" Grid.Column="1" Foreground="{TemplateBinding Foreground}" Height="24" IsTabStop="False" Template="{StaticResource PhoneProgressBarSliderThumb}"/>
                                <RepeatButton x:Name="HorizontalTrackLargeChangeIncreaseRepeatButton" Grid.Column="2" Height="0" Template="{x:Null}"/>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ProgressBarStyle1" TargetType="ProgressBar">
            <Setter Property="Height" Value="30"/>
            <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
            <Setter Property="Background" Value="{StaticResource PhoneAccentBrush}"/>
            <Setter Property="Maximum" Value="100"/>
            <Setter Property="IsHitTestVisible" Value="False"/>
            <Setter Property="Padding" Value="{StaticResource PhoneHorizontalMargin}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ProgressBar">
                        <Grid>
                            <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>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DeterminateRoot">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Value" Storyboard.TargetName="Slider1">
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="1000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="2000"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="3000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseIn" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="Value" Storyboard.TargetName="Slider2">
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="1000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="2000"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="3000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseIn" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="Value" Storyboard.TargetName="Slider3">
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="1000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="2000"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="3000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseIn" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.6" Storyboard.TargetProperty="Value" Storyboard.TargetName="Slider4">
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="1000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="2000"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="3000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseIn" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8" Storyboard.TargetProperty="Value" Storyboard.TargetName="Slider5">
                                                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="1000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="2000"/>
                                                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="3000">
                                                    <EasingDoubleKeyFrame.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseIn" Exponent="1"/>
                                                    </EasingDoubleKeyFrame.EasingFunction>
                                                </EasingDoubleKeyFrame>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Slider1">
                                                <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="Slider2">
                                                <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="Slider3">
                                                <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="Slider4">
                                                <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="Slider5">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
                                                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name="DeterminateRoot" Margin="{TemplateBinding Padding}" Visibility="Visible">
                                <Rectangle x:Name="ProgressBarTrack" Fill="{TemplateBinding Background}" Height="24" Opacity="0.1"/>
                                <Rectangle x:Name="ProgressBarIndicator" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Left" Height="24"/>
                            </Grid>
                            <Border x:Name="IndeterminateRoot" Margin="{TemplateBinding Padding}" Visibility="Collapsed">
                                <Grid>
                                    <Slider x:Name="Slider1" Foreground="{TemplateBinding Foreground}" Style="{StaticResource PhoneProgressBarSliderStyle}"/>
                                    <Slider x:Name="Slider2" Foreground="{TemplateBinding Foreground}" Style="{StaticResource PhoneProgressBarSliderStyle}"/>
                                    <Slider x:Name="Slider3" Foreground="{TemplateBinding Foreground}" Style="{StaticResource PhoneProgressBarSliderStyle}"/>
                                    <Slider x:Name="Slider4" Foreground="{TemplateBinding Foreground}" Style="{StaticResource PhoneProgressBarSliderStyle}"/>
                                    <Slider x:Name="Slider5" Foreground="{TemplateBinding Foreground}" Style="{StaticResource PhoneProgressBarSliderStyle}"/>
                                </Grid>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    

    【讨论】:

    • 易如反掌... 一个问题:为什么我们也需要最后两个更改? (拇指的)。改变矩形的高度就可以了。
    • 我猜它们是用于点加载进度条的,如果你不需要它们,你可以保持原样,我只是觉得最好让它们保持一致。 :)
    【解决方案2】:
    <ProgressBar Width="300" Background="White" Foreground="Red" Height="28" Margin="78,0"   RenderTransformOrigin="0.5,0.5">
        <ProgressBar.RenderTransform>
        <CompositeTransform ScaleY="-5"/>
        </ProgressBar.RenderTransform>
    </ProgressBar>
    

    【讨论】:

    • 完美(而且更简单)的解决方案!
    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 2023-02-06
    • 1970-01-01
    相关资源
    最近更新 更多