2
我有一個WPF,Vista風格的進度條,我想改變畫筆。我已經將前景刷設置爲另一種顏色,但有一種顏色仍然是默認綠色的動畫效果。我該如何改變這一點?你如何改變WPF進度條上的顏色
我有一個WPF,Vista風格的進度條,我想改變畫筆。我已經將前景刷設置爲另一種顏色,但有一種顏色仍然是默認綠色的動畫效果。我該如何改變這一點?你如何改變WPF進度條上的顏色
爲此,您需要編輯項目中進度條控件的ControlTemplate樣式。使用這些樣式
<Style x:Key="{x:Type ProgressBar}"
TargetType="{x:Type ProgressBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid MinHeight="14" MinWidth="200">
<Border
Name="PART_Track"
CornerRadius="2"
Background="{StaticResource PressedBrush}"
BorderBrush="{StaticResource SolidBorderBrush}"
BorderThickness="1" />
<Border
Name="PART_Indicator"
CornerRadius="2"
Background="{StaticResource DarkBrush}"
BorderBrush="{StaticResource NormalBorderBrush}"
BorderThickness="1"
HorizontalAlignment="Left" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
例子:
<LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#BBB" Offset="0.0"/>
<GradientStop Color="#EEE" Offset="0.1"/>
<GradientStop Color="#EEE" Offset="0.9"/>
<GradientStop Color="#FFF" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
...
<SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />
...
<LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#AAA" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
...
<LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#CCC" Offset="0.0"/>
<GradientStop Color="#444" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
你可以看到在MSDN上的這樣一個例子:ProgressBar ControlTemplate Example