Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Bug in RangeBase (affects ProgressBar)
2 replies. Latest Post by andulvar on November 6, 2009.
(0)
Eloff
Member
139 points
114 Posts
08-08-2009 10:39 PM |
A common way to use ProgressBar is to set Maximum to 1, and Value to a number between 0 and 1 (treating it as percent completed.) This can cause ProgressBar to fail where larger numbers would have worked. The implementation of RangeBase (verified using reflector) calls DoubleUtil.AreClose(newValue, oldValue) and if they are close, it makes no change. This is fine, except that oldValue should be a member variable that is set ONLY every time the condition is true. Currently oldValue is the last value that was set regardless of whether any action was taken. The effect is that if you set RangeBase.Value to slightly increasing values each time, small enough that DoubleUtil.AreClose(newValue, oldValue) returns true, then it will behave as if the value is not changing at all. I verified that you can increase the value from 0 all the way to 1 in many small increments and the ProgressBar will not move. It's not a serious bug, but the fix, as I outlined of using an additional private member variable, is very simple. Sincerely, -Dan
Jonathan...
All-Star
24979 points
2,434 Posts
08-14-2009 6:36 AM |
Hi Dan,
Would you please the code segment that you did to fix the issue? Thanks.
Best regards,
Jonathan
andulvar
155 points
102 Posts
11-06-2009 3:47 PM |
There is another bug in RangeBase. If the CoerceValue code ever calls SetValue(ValueProperty,...) then Silverlight will stop sending value changes through the binding to the RangeBase. I suspect this is an incompatibility between Silverlight 2 and Silverlight 3. The coercion for Minimum and Maximum do not suffer from this problem.
You can change CoerceValue() to this code, which seems to work just fine, though it removes DoubleUtil.AreClose, which is still buggy as described above anyway.
private void CoerceValue() { double minimum = this.Minimum; double maximum = this.Maximum; //double num3 = this.Value; if (this._requestedVal < minimum) this._requestedVal = minimum; if (this._requestedVal > maximum) this._requestedVal = maximum; //if ((!DoubleUtil.AreClose(this._requestedVal, num3) && (this._requestedVal >= minimum)) && (this._requestedVal <= maximum)) //{ // base.SetValue(ValueProperty, this._requestedVal); //} //else //{ // if (num3 < minimum) // { // base.SetValue(ValueProperty, minimum); // } // if (num3 > maximum) // { // base.SetValue(ValueProperty, maximum); // } //} }