我想要一个进度条根据当前值当前所在的范围来更改其颜色。我想知道进度条上是否有一个属性,我可以将视图模型属性绑定到该属性来更改颜色。 WPF进度条上是否存在这样的属性?
只需将前景色更改为您喜欢的颜色即可:
<ProgressBar Foreground="{Binding PBarColorBrush}" Value="{Binding PBarValue}" />
Edit(回答你的评论):是的,你需要一个Brush
属性(WPF 中几乎所有颜色属性都是 Brushed)
但不用担心,这很简单:
Public Sub DoWork()
For i = 1 To 100
If i < 50 Then
PBarColorBrush = Brushes.Blue
ElseIf i < 80 Then
PBarColorBrush = Brushes.Green
Else
PBarColorBrush = Brushes.Red
End If
Next
End Sub
以及财产:
Private _PBarColorBrush As Brush
Public Property PBarColorBrush() As Brush
Get
Return _PBarColorBrush
End Get
Set(ByVal value As Brush)
_PBarColorBrush = value
OnPropertyChanged("PBarColorBrush")
End Set
End Property
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)