I have a progressbar and its value is binded to a property:
<ProgressBar x:Name="progressBar"
Margin="0,2,0,0"
Height="20"
Value="{Binding CompassLogLoadPercent}"
Foreground="Blue"
Visibility="{Binding CompassLogLoadCompleted,
Converter={StaticResource BooleanToVisibilityConverter}}"
ToolTip="Loading">
</ProgressBar>
and the property:
public double CompassLogLoadPercent {
get { return _compassLogLoadPercent; }
private set {
if (value != _compassLogLoadPercent) {
_compassLogLoadPercent = value;
NotifyPropertyChanged();
}
}
}
and in a seperate thread its value is updated:
for (int j = 0; j < lines.Count(); j++) {
...
CompassLogLoadPercent = ((double) j /lines.Count())*100;
}
and the thread is created using TASK:
Task.Run(() => { LoadLogFile(fileName); });
Why is progressbar not updating and how should I fix this?
UPDATE: More Info
Datacontext: (Im sure that the dataContext is Correct)
cLT.progressBar.DataContext = logSession;
and implementation of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged(
[CallerMemberName] String propertyName = "") {
PropertyChangedEventHandler eventHandler = PropertyChanged;
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) {
handler(this, new PropertyChangedEventArgs(propertyName));
}
}