I have a question about ProgressBar
in WPF in C#. I want that my progressBar
will have 2 colors. For example I set his max value to 25 and in seventh and fifth iteration something goes wrong and I want it in red color in my progressbar
.
I added example picture what I want gain to.
You could use a GradiantBrush
and set the GradientStops
based on your logic, the only downside to this solution is that GradientStops
aren't bindable so you have to set them from code. Here is a simple taste:
<ProgressBar Width="500" Value="70" Height="30">
<ProgressBar.Foreground>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0" >
<GradientStop Color="Green" Offset="0" />
<GradientStop Color="Green" Offset="0.3" />
<GradientStop Color="Red" Offset="0.3" />
<GradientStop Color="Red" Offset="0.5" />
<GradientStop Color="Green" Offset="0.5" />
<GradientStop Color="Green" Offset="1" />
</LinearGradientBrush>
</ProgressBar.Foreground>
</ProgressBar>
Output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With