Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProgressBar 2 colors

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.

enter image description here

like image 331
konto zprzypadku Avatar asked Nov 07 '22 09:11

konto zprzypadku


1 Answers

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:

enter image description here

like image 163
SamTh3D3v Avatar answered Nov 15 '22 07:11

SamTh3D3v