简体   繁体   English

WP7 ProgressBar高度和颜色问题

[英]WP7 ProgressBar Height and Colour Troubles

I'd like to change the height of the progress bar within my project however the height property doesn't seem to be doing anything when I set it. 我想更改项目中进度条的高度,但是当我设置height属性时,它似乎没有任何作用。 Also, is it possible to change the colour of the progress bar from the default blue to another colour? 另外,是否可以将进度条的颜色从默认的蓝色更改为另一种颜色? Orange for example. 例如橙色。

The ProgressBar have two colours. ProgressBar有两种颜色。 A background, which is the background of the ProgressBar at all times, and the foreground which is the colour of the ProgressBar when it have a Value that's greater than the minimum. 背景(始终是ProgressBar的背景),前景是ProgressBar(其值大于最小值时)的颜色。 Both can be customized easily, but keep in mind that it defaults to using the Accent colour of the phone, which is recommended, unless you have a really good reason. 两者都可以很容易地进行定制,但请记住,它默认使用手机,这是建议,除非你有一个很好的理由的强调文字颜色。

To change the actual height, override it's ControlTemplate, and change the height of the ProgressBarIndicator and the ProgressBarTrack , like this: (here set to 20px) 要更改实际高度,请覆盖它的ControlTemplate,然后更改ProgressBarIndicatorProgressBarTrack的高度,如下所示:(此处设置为20px)

<Style TargetType="ProgressBar">
    <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>
                        <!-- Visual States removed for clarity -->
                    </VisualStateManager.VisualStateGroups>
                    <Grid x:Name="DeterminateRoot" Margin="{TemplateBinding Padding}" Visibility="Visible">


                        <!-- CHANGE THE HEIGHT HERE -->
                        <Rectangle x:Name="ProgressBarTrack" Fill="{TemplateBinding Background}" Height="20" Opacity="0.1"/>
                        <Rectangle x:Name="ProgressBarIndicator" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Left" Height="20"/>


                    </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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM