PropertyEditor Used in PropertyGrid Swallowing Undo/Redo Events

Grids for WPF Forum

The latest build of this product (v2018.1 build 0675) was released 2 months ago, which was before this thread was created.
Posted 2 months ago by Nate Smith
Version: 18.1.0675
Avatar

I am using the PropertyGrid and a derivation of an Int32PropertyEditor.  The only things I do in my derivation are set the Minimum to 0 (so it's positive numbers only) and force the SpinnerVisibility to Visible.  Then I use the [Editor] attribute on my model classes to allow the PropertyGrid to build itself.

The model properties look something like this:

[DisplayName("LG Columns")]
[Description("The number of columns the control will occupy when the viewport is large")]
[Editor(typeof(PositiveInt32EditorWithSpinner), typeof(PropertyEditor))]
public int LargeColumns { get; set; }

I have my ViewModels handling property changes through your PropertyGrid's PropertyValueChanging and PropertyValueChanged events.  The problem arrises when I make changes to the integer values using the spinner and then press Ctrl+Z to Undo or Ctrl-Y to Redo.  When the TextBox portion of the editor has focus it performs the Undo/Redo locally just on the EditBox and the Undo or Redo event does not bubble up to my application's MainWindow so that I can handle it.  These events swallowed by the TextBox and the PropertyGrid's PropertyValueChanging and PropertyValueChanged do not fire.  Everything is fine if the TextBox portion of the editor does not have focus.

Any solution to this?

Comments (7)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Nate,

If I understand correctly, you are seeing the value change events fire when using the spinner, but if you do Undo/Redo in the TextBox, they don't fire, and that is the problem?

Do the value change events fire once focus leaves the TextBox?  If so, you might want to alter the edit box's CommitTriggers.  They default to only committing when focus leaves the control, Enter is pressed, or a spin occurs.


Actipro Software Support

Posted 2 months ago by Nate Smith
Avatar

Not exactly.  I did change the CommitTriggers to update the property and it fires, but that's still a problem, because my application is never getting the Undo/Redo events and therefore I can't manage them.  The property change events fire with the Undo/Redo but that's not what is needed since there is no distinction between a change caused by clicking the spinner and a change caused by Undo/Redo.

For example, if the value is 1 and I click up twice, then click down twice, I get 4 property changed events and my Undo stack has 4 items in it.  However, if the value is 1 and I click up twice, then press Ctrl+Z twice, because the PropertyEditor is handling and swallowing the Ctrl+Z Undo request, I also get 4 property changed events, and my Undo stack has 4 items in it.  I want to handle that Ctrl+Z Undo request in my application and roll those changes back.  I shoulld get those requests, pop those Undo actions off the stack, and after pressing Ctrl+Z twice, I should have zero items in my Undo stack.

[Modified 2 months ago]

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Nate,

The edit box basically has a native WPF TextBox in its Template.  We do attach to some of the TextBox's events, but I don't believe we mark thme as handled or anything.  Could you look for and handle the TextBox.TextChanged event to examine its e.UndoAction?  I assume that event would bubble up.


Actipro Software Support

Posted 2 months ago by Nate Smith
Avatar

I can see no way to get to the TextBox (through inheritance at least.)  I guess I'll have to read up on using the 'default templates' and just roll my own editor.  There really should be a way to enable/disable the Undo/Redo behavior on the Editor since rather then it always be enabled in the TextBox portion.  https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.textboxbase.isundoenabled?redirectedfrom=MSDN&view=netframework-4.7.2#System_Windows_Controls_Primitives_TextBoxBase_IsUndoEnabled

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

The edit boxes are custom controls that don't inherit TextBox.  Instead a TextBox instance is within the template of the edit box controls.  Thus it's nested within the visual hierarchy of the edit box control.

If we added an IsUndoEnabled property to the edit box that would effectively bind to the contained TextBox's IsUndoEnabled property, would that solve your problem since then you could block the undo/redo within the TextBox itself?


Actipro Software Support

Posted 2 months ago by Nate Smith
Avatar

I believe that is exactly what I need.  This is assuming there isn't another child control (like the spinner) that is intercepting the Undo/Redo events.  I just need them ignored by the editor and I need them to bubble up to the application so I can handle them myself.  Thanks!

Answer - Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Nate,

Ok we will add an IsUndoEnabled property to the edit boxes for the next build.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.