TypeSpecificPartBase and CoerceValue

Editors for WPF Forum

Posted 15 years ago by Ray Wallace
Version: 9.1.0502
I've got a Part derived from TypeSpecificBase<decimal> whose Value I'm trying to constrain between two values. I've overridden CoerceValue like so:

protected override decimal CoerceValue(decimal value) {
  if (value > this.Maximum)
    value = this.Maximum;
  else if (value < this.Minimum)
    value = this.Minimum;

  return value;
On the face of it, this works. The Value of the part is kept between Maximum and Minimum. However, this doesn't adjust the string value that's displayed on the screen. I tried overriding OnValueChanged like so:

protected override void OnValueChanged(decimal oldValue, decimal newValue){                                                                
  base.OnValueChanged(oldValue, newValue);
  this.DisplayValue = newValue;
Which is a bit like how I handle increment and decrement for the spin buttons (which work). And like before, this almost works. The DisplayValue of the part is set correctly and the StringValue looks correct - but the value that's displayed on the screen still isn't adjusted to match.

I've also tried overriding CoerceValue on the part group and edit box that the part is in, which also hasn't affected the value displayed on the screen. Is there some property or method call I'm missing?

Comments (2)

Posted 15 years ago by Ray Wallace
So, in the GenerateDefaultItems of TypeSpecificTextBox<Decimal> that contains the above part I had the following line:

(DecimalPartGroup being a TypeSpecificPartGroup<Decimal>)

Removing the line fixed the issue. In my use of the text box I was explicitly setting PartValueCommitTriggers to All. Why does this binding cause a problem? I have no idea.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Ray,

You may be better off using the RangeTypeSpecificPartBase<T>, as that has the Minimum and Maximum properties already defined. Our part implementations, typically enforce the min/max in the TryGetEffectiveValue method. Any changes you apply there should be reflected in the display.

You should only use the SyncBinding for things that need two-way binding *and* need to be able to push coerced values back. For your purposes, you should only need to use that on InitialValue and Value. The other properties can just use a native WPF Binding.

If you can put together a small sample project and send it over to our support address, then we can take a look.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.