C#XAML进度设置渐变填充正确 [英] c# XAML ProgressBar set gradient filling properly
问题描述
我如何在XAML中设置的进度
梯度动态填充?
How do I set the gradient of a ProgressBar
in XAML to dynamic filling?
目前其这样的:
代码为进度条:
<ProgressBar.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<LinearGradientBrush.RelativeTransform>
<CompositeTransform CenterY="0.5" CenterX="0.5" Rotation="270"/>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="Lime" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</ProgressBar.Foreground>
但我想有结束上进度<色/ code>在绿黄色的色似正下方。
意味着我要在进度条满打满像第二个栏,然后切割休息了(例如,当我有60%我想40%的右未显示)
but I want to have the "end"color of the upper ProgressBar
in the green-yellowish color like directly below.
Means I want the progress bar full filled like the second bar and then "cut" the rest out (e.g. when I have 60% I want the 40% on the right not shown)
我如何做正确
编辑(找到了解决方法):
Edit (found a solution):
试图通过几种方式(绘图默认色的矩形到酒吧等)后,我想通了,我可以修改偏移
渐变停止<中> / code>通过代码:
After trying a couple of ways (drawing a rectangle with default color onto the bar etc) I figured out that I can modify the offset
of GradientStop
by code:
color_UL.Offset = 2.0 - ul_val / 100;
意味着我减去我要显示例如百分比30%( ul_val = 30
)的偏移量设定为170%(1.7),但酒吧本身就说明与光滑和正确的颜色渐变30%。如果我有栏上100%,它计算 2.0 - 1.0
为1(如正常,图片1显示在酒吧#2)
means I subtract the percentage that I want to display e.g. 30% (ul_val = 30
) the Offset is set to 170% (1.7) but the bar itself shows 30% with the smooth and right color gradient. If I have 100% on the bar it calculates 2.0 - 1.0
which is 1 (like normal, shown in Bar #2 in picture 1).
我知道这听起来都令人困惑,所以这里的图片,我想它是:
I know this sounds all confusing, so here the picture as I wanted it to be:
推荐答案
我的解决方案:
尝试几种方法(绘图默认色的矩形到酒吧等)后,我想通了,我可以修改偏移
渐变停止
由代码:
After trying a couple of ways (drawing a rectangle with default color onto the bar etc) I figured out that I can modify the offset
of GradientStop
by code:
color_UL.Offset = 2.0 - ul_val / 100;
意味着我减去我要显示例如百分比30%( ul_val = 30
)的偏移量设定为170%(1.7),但酒吧本身就说明与光滑和正确的颜色渐变30%。如果我有栏上100%,它计算 2.0 - 1.0
为1(如正常,图片1显示在酒吧#2)
means I subtract the percentage that I want to display e.g. 30% (ul_val = 30
) the Offset is set to 170% (1.7) but the bar itself shows 30% with the smooth and right color gradient. If I have 100% on the bar it calculates 2.0 - 1.0
which is 1 (like normal, shown in Bar #2 in picture 1).
我知道这听起来都令人困惑,所以这里的图片,我想它是:
I know this sounds all confusing, so here the picture as I wanted it to be:
这篇关于C#XAML进度设置渐变填充正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!