我想在项目中更改进度条的高度,但是当我设置它时,height属性似乎没有做任何事情。此外,是否可以将进度条的颜色从默认蓝色更改为另一种颜色?例如,橙色。
答案 0 :(得分:5)
ProgressBar有两种颜色。一个背景,它始终是ProgressBar的背景,前景是ProgressBar的颜色大于最小值时的颜色。两者都可以轻松定制,但请记住,除非您有真正的充分理由,否则默认使用手机的强调色,这是推荐的。
要更改实际高度,请覆盖它的ControlTemplate,然后更改ProgressBarIndicator
和ProgressBarTrack
的高度,如下所示:(此处设置为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>