Skip to main content

Microsoft Silverlight

Answered Question Bug in RangeBase (affects ProgressBar)RSS Feed

(0)

Eloff
Eloff

Member

Member

139 points

114 Posts

Bug in RangeBase (affects ProgressBar)

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 Shen – MSFT
Jonathan...

All-Star

All-Star

24979 points

2,434 Posts

Microsoft

Re: Bug in RangeBase (affects ProgressBar)

Hi Dan,

Would you please the code segment that you did to fix the issue?  Thanks.

Best regards,

Jonathan

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

andulvar
andulvar

Member

Member

155 points

102 Posts

Answered Question

Re: Bug in RangeBase (affects ProgressBar)

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);
            //    }
            //}
        }
  

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities