简体   繁体   English

带有多个 colors WPF 的进度条

[英]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!欢迎来到 SO!

Just set that indicator's width to the same as that of the parent ProgressBar:只需将该指标的宽度设置为与父 ProgressBar 的宽度相同:

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

Simple!简单的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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