Chroma ProgressBar 2

I have a question about ProgressBar in WPF in C #. I want my ProgressBar have 2 colors. For example, I set its maximum value to 25, and in the seventh and fifth iteration, something went wrong, and I want it in red in my ProgressBar . I added an example image that I want to get.

enter image description here

+5
source share
1 answer

You can use GradiantBrush and install GradientStops based on your logic, the only drawback of this solution is that GradientStops are not bindable, so you have to install them from the 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:

enter image description here

+1
source

Source: https://habr.com/ru/post/1275996/


All Articles