2010-08-18 36 views

回答

2

只要改變前景色的顏色你喜歡:

<ProgressBar Foreground="{Binding PBarColorBrush}" Value="{Binding PBarValue}" /> 

編輯(回答您的評論):是的,你需要一個Brush財產(幾乎所有的顏色屬性在WPF拉絲)

但不要擔心,這是非常簡單的:

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 
+0

因此將Foreground綁定到System.Drawing.Color屬性? – BrianP 2010-08-18 18:41:44

+0

換句話說,在你的例子中「PBarColorBruch」是一個Color屬性? – BrianP 2010-08-18 18:42:34

+1

你要麼公開'Brush'屬性(不是一種顏色),或者,如果這是你要使用的東西,建立一個'int'到''brush'轉換器。 – 2010-08-18 18:54:21

0

您是否試圖更改進度條的整個顏色,或者您是否試圖根據值將不同部分的進度條改爲不同的顏色?如果後者您需要漸變畫筆,請根據進度欄中的值設置不同的漸變光圈。

+0

進度條的整個顏色 – BrianP 2010-08-19 13:47:53

相關問題