到目前为止,我一直在搜索这个问题,找不到任何答案对我没有帮助。 我对wpf真的很陌生,我不知道如何实现这一目标。 我需要让进度条在达到某个值或百分比时改变它的颜色,或者其他什么。
提前致谢
这是我的代码 XAML
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:MainWindow x:Key="ProgressForegroundConverter"/>
</Window.Resources>
<StackPanel>
<ProgressBar Margin="20"
Value="{Binding ElementName=progress, Path=Value}"
Foreground="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value, Converter={StaticResource ProgressForegroundConverter}}" Height="38"/>
<Slider Name="progress" Margin="10" Minimum="0" Maximum="100"/>
</StackPanel>
app XAML
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
vb.net
Class MainWindow
Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfoIetfLanguageTagConverter)
Dim progress As Double = value / 100
Foreground = Brushes.Red
If progress = 100D Then
Foreground = Brushes.Green
ElseIf progress >= 95D Then
Foreground = Brushes.Yellow
End If
Return Foreground
End Function
Public Function ConvertBack(ByVal value As Object, targetType As Type, parameter As Object, culture As CultureInfoIetfLanguageTagConverter)
Throw New NotImplementedException()
End Function
End Class