I have a progress bar bound to 2 integer values - One is the total seconds and the other is the seconds left (which counts down on a timer: always <= Total seconds).
I have the LayoutRoot datacontext set to my top level object (of which BlindSet is a property -see code).
When I run the project the progress bar updates perfectly. It counts down the number of seconds as expected. I then change the datacontext by instantiating a new object and setting it to the BlindSet class. I use DataChanged notification events to let the UI know it has changed. This also works well - all other controls, EXCEPT the progress bar, update accordingly.
It's got me baffled, so I simplified it down to this:
2 textblocks and the progress bar, all bound to the same values. The datacontext is set higher up so it's the same for all of them.
The textblocks show the correct values counting down. (BlindSet.TimeLeftInCurrentBlind.TotalSeconds counts down on a timer) but the progress bar never updates again after I change the datacontext. I even tried rebinding it after the datacontext change but that did not help.
I also bind the ToolTip on the progress bar to the same value as Value is set to - and when you hover over the non-updating progress bar you can see it counting down correctly... but the progress bar does not show it.
Either I am doing something really stupid (possible ;) or it is a bug in the progress bar control.
xaml:
<TextBlock Text="{Binding BlindSet.CurrentBlind.SecondsPerBlind}" />
<TextBlock Text="{Binding BlindSet.TimeLeftInCurrentBlind.TotalSeconds}" />
<ProgressBar Minimum="0" Maximum="{Binding BlindSet.CurrentBlind.SecondsPerBlind}" Value="{Binding BlindSet.TimeLeftInCurrentBlind.TotalSeconds}" ToolTipService.ToolTip="{Binding BlindSet.TimeLeftInCurrentBlind.SecondsPerBlind}" />
Code behind:
LayoutRoot.DataContext = tournament;
tournament has a BlindSet object, but I don't think this is part of the problem as the other controls are updating fine:
public Blindset BlindSet
{
get { return blindset; }
set
{
if (blindset != value)
{
blindset = value;
OnPropertyChanged("BlindSet");
OnPropertyChanged("CurrentBlind");
}
}
}
Update: Perhaps there is some internal state that needs to be reinitialised with the new max and value values when the datacontext changes (the values are very different, e.g 1200 seconds or 120 seconds).
When I bind to a new BlindSet object with the same values (ie. 1200 seconds) then it works as expected - so I think I need to somehow give it a kick to recalculate the small or large value changes - any idea how?!