Josh
On Wednesday, March 30, 2011, Bill Kempf <wek...@gmail.com> wrote:
> I've got a NumericUpDown implementation done in WPF that's very similar to implementations you can find just about everywhere, including when in the "Extended WPF Toolkit" (http://wpftoolkit.codeplex.com). I have no idea if this project has any official connection to the actual WPF Toolkit and thus to Microsoft, but suffice it to say the issue I'm about to discuss is in nearly every NumericUpDown implementation I can find. Here's what you do to produce the problem.
> Add a NumericUpDown to your window and set a Minimum (10) and Maximum (100) value, then bind the Value to a property on your ViewModel (or just do it in the codebehind to make the sample simple). Set a break point on your property's setter. Run the application and use the up button to increment the Value and show that your break point gets hit and that everything is working. Now, use the edit portion to manually set the value to something less than the Minimum (-1) and tab out of the control. Your break point will get hit, but note that the value being set is the value you entered in the control (-1). Continue running and note that the control actually shows the Minimum (10) value.
> What's happening is that the Value DependencyProperty is using a CoerceValueCallback to ensure the values remain in range. However, what happens when you do this is FUBAR. When you call SetValue on the DependencyProperty this is roughly what happens:
> 1. Any BindingExpression sources are updated with the value.2. The CoerceValueCallback (if present) is called to coerce the value.3. The coerced value is used to set the actual DependencyValue property.
I don't want to rehash old territory here, but this apathy and malaise
is causing a lot of vocal resentment. Add to this things like the
recent NoDo farce and MS looks amateurish.