简体   繁体   English

ProgressBar 2种颜色

[英]ProgressBar 2 colors

I have a question about ProgressBar in WPF in C#. 我在C#中的WPF中有关于ProgressBar的问题。 I want that my progressBar will have 2 colors. 我希望我的progressBar有两种颜色。 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 . 例如,我将他的最大值设置为25,并且在第七次和第五次迭代中出现问题,我希望它在我的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. 您可以使用GradiantBrush并根据您的逻辑设置GradientStops ,此解决方案的唯一缺点是GradientStops不可绑定,因此您必须从代码中设置它们。 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: 输出:

在此输入图像描述

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

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