简体   繁体   中英

Progressbar with multiple colors WPF

i'm trying to make my progressbar look like this:

在此处输入图像描述

在此处输入图像描述

But i have this instead:

在此处输入图像描述

This is the code i have (i created a style for the progressbar with the property "fill" of the indicator):

<Rectangle x:Name="Indicator"  >
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint="0,0" StartPoint="1,0">
                                        <GradientStop Color="Red" Offset="0"/>
                                        <GradientStop Color="Yellow" Offset="0.5"/>
                                        <GradientStop Color="Green" Offset="1"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>


                            </Rectangle>

Welcome to SO!

Just set that indicator's width to the same as that of the parent ProgressBar:

<Rectangle x:Name="Indicator" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ProgressBar}}">

Simple!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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