0

I want change progressbar to like this: enter image description here

,and I set its ForgroundColor in xaml:

<ProgressBar x:Name="pbTotal2" Margin="5,0,0,0" Foreground="#008BCA" VerticalAlignment="Center" Height="24" Width="800" ></ProgressBar>

but the result is: enter image description here I tried other colors, but the result doesn't change,Anyone can help me to solve this?

starkshang
  • 8,228
  • 6
  • 41
  • 52
  • 1
    Possible duplicate of [WPF progressbar style](http://stackoverflow.com/questions/4815175/wpf-progressbar-style) – ASh Apr 06 '17 at 08:42
  • @ASh,I don't think it's the same, my code doesn't disagree with his, but i can't change the color as expected, how can you explain this? – starkshang Apr 06 '17 at 08:46
  • the problem is that your picking up the default windows theme, you need to override this either by choosing a simpler style or just styling the correct sub element of the progress bar – MikeT Apr 06 '17 at 08:47

1 Answers1

0

The difference between the two progressbars is not just the foreground color it is the whole style, so you have to write the style you want by your self, see these pages:

https://msdn.microsoft.com/en-us/library/dd334413(v=vs.95).aspx

https://msdn.microsoft.com/en-us/library/ms750638(v=vs.110).aspx

ZORRO_BLANCO
  • 849
  • 13
  • 25
  • you need to quote the correct section of the page as links can more or change over time making your answer meaningless – MikeT Apr 06 '17 at 08:51
  • I just want to change the color,can't i change the foreground only? – starkshang Apr 06 '17 at 08:51
  • @starkshang the foreground is the font colour only under the theme on your system – MikeT Apr 06 '17 at 08:52
  • @MikeT, then what attritute should i change? – starkshang Apr 06 '17 at 08:54
  • @starkshang you need to override the style of the ProgressBarIndicator look at these sections of the link suggested by ASh – MikeT Apr 06 '17 at 08:57
  • @starkshang or see the whole description in the links i suggested – ZORRO_BLANCO Apr 06 '17 at 09:08
  • @ZORRO_BLANCOZ, thanks for your suggestion, but if i want to change the color,what attritute should i change, What i need to do is define the style with key "MyProgressbar" and use the style on my progressbar with Style={StaticResource MyProgressbar}? – starkshang Apr 06 '17 at 09:14
  • you are welcome, and you can change the color in the styles that are in the links by changing the LinearGradientBrush you should add only two GradientStop one with offset 0 and the other with offset 1 and same color for both will give you one color for the whole progressbar: – ZORRO_BLANCO Apr 07 '17 at 08:41