-1
我試圖在代碼中動態更改進度條的前景色,但設置顏色的常用分配對於進度條不起作用。如何以編程方式設置進度條的前景色?
這是我正在嘗試設置前景色:
ProgressBar.Foreground = new SolidColorBrush(Colors.Green);
但我得到的錯誤是:
的對象引用是必需的非靜態字段或方法 財產, 'system.windows.controls.control.foreground.get'
這是進度條的XAML聲明:
<ProgressBar IsIndeterminate="False" x:Name="workProgressBar" Maximum="100" Foreground="BlueViolet" Margin="59,185,55,295" FontWeight="Bold" Style="{StaticResource ProgressBarStyle3}"/>
有誰知道如何以編程方式設置前景顏色?
聽起來像是'ProgressBar'不是'static'類,這就是爲什麼callind'Foreground'方法需要一個'ProgressBar'類的參考。嘗試用'ProgressBar p = new ProgressBar(); p.Foreground =新的SolidColorBrush(Colors.Green);' – 2014-12-04 12:41:37
聽起來像你的ProgressBar不叫ProgressBar - 也許你可以包含定義它的XAML? – 2014-12-04 12:43:46