你如何改变一个WPF进度条的颜色 [英] How do you change the colors on a WPF progressbar

查看:1014
本文介绍了你如何改变一个WPF进度条的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想上更改刷一个WPF,Vista的风格进度。我已经设置前景刷到另一种颜色,但有一个排序的呼呼声动画效果,其色彩仍然是默认的绿色。我怎样才能改变呢?

I have a WPF, vista style progressbar that I want to change the brushes on. I've set the foreground brush to another color, but there is a sort of whoosh animation effect whose color is still the default green. How can I change this?

推荐答案

要做到这一点,你需要在你的项目中的进度条控件编辑控件模板样式。

To do this you need to edit the ControlTemplate Styles for the Progress Bar control in your project.

<Style x:Key="{x:Type ProgressBar}"
     TargetType="{x:Type ProgressBar}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ProgressBar}">
        <Grid MinHeight="14" MinWidth="200">
          <Border 
            Name="PART_Track" 
            CornerRadius="2" 
            Background="{StaticResource PressedBrush}"
            BorderBrush="{StaticResource SolidBorderBrush}"
            BorderThickness="1" />
          <Border 
            Name="PART_Indicator" 
            CornerRadius="2" 
            Background="{StaticResource DarkBrush}" 
            BorderBrush="{StaticResource NormalBorderBrush}" 
            BorderThickness="1" 
            HorizontalAlignment="Left" />
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

示例使用这些样式:

<LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
  <GradientBrush.GradientStops>
    <GradientStopCollection>
      <GradientStop Color="#BBB" Offset="0.0"/>
      <GradientStop Color="#EEE" Offset="0.1"/>
      <GradientStop Color="#EEE" Offset="0.9"/>
      <GradientStop Color="#FFF" Offset="1.0"/>
    </GradientStopCollection>
  </GradientBrush.GradientStops>
</LinearGradientBrush>


...


<SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />


...


<LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
  <GradientBrush.GradientStops>
    <GradientStopCollection>
      <GradientStop Color="#FFF" Offset="0.0"/>
      <GradientStop Color="#AAA" Offset="1.0"/>
    </GradientStopCollection>
  </GradientBrush.GradientStops>
</LinearGradientBrush>


...


<LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
  <GradientBrush.GradientStops>
    <GradientStopCollection>
      <GradientStop Color="#CCC" Offset="0.0"/>
      <GradientStop Color="#444" Offset="1.0"/>
    </GradientStopCollection>
  </GradientBrush.GradientStops>
</LinearGradientBrush>

您可以看到这个MSDN上的例子:ProgressBar控件模板实例

You can see an example of this on MSDN: ProgressBar ControlTemplate Example

这篇关于你如何改变一个WPF进度条的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆