I'm searching for this so far and none of the found answer didn't helped me. I'm really new to wpf, and i have no clue on how to accomplish that. I need to make a progressbar changes it's color upon reaching a certain value or percentage, or whatever.
Thanks in advance
Here's my code 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