简体   繁体   English

如何更改WPF进度条上的颜色

[英]How do you change the colors on a WPF progressbar

I have a WPF, vista style progressbar that I want to change the brushes on. 我有一个WPF,vista样式进度条,我想更改画笔。 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. 为此,您需要在项目中编辑Progress Bar控件的ControlTemplate样式。

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

Example using these styles: 使用这些样式的示例:

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

You can see an example of this on MSDN: ProgressBar ControlTemplate Example 您可以在MSDN上看到此示例: ProgressBar ControlTemplate示例

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

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