What is needed to support undo/redo in the XamComboEditor (outside of a Xamdatagrid) and XamTextEditor and XamComboEditor (Inside of a XamDatagrid).
to best illustrate the issue I am encountering, please refer your 9.2 xamFeatureBrowser Samples.
Situation #1: run the XamDatagrid -> Layout and Behavior -> Add record sample. Edit the title field. press ctrl+Z and ctrl+Y. you see that undo redo works. select a different column, then return to the same field that was edited before and ctrl-Z and ctrl+Y - notice that no undo functionality occurs now.
Situation #2: run the XamDatagrid -> Control Composition -> XamComboEditor in Datarecord Cells sample. change the value within the Priority Column. Press Ctrl+Z ctrl+Y. notice no undo redo functionality exists. if you have a XamComboEditor that has AllowEdit = true. and you do the above action (Select a new value from the dropdown) undo redo works. but if the control looses focus - then focus returns - there is no undo redo functionality.
To make matters worse - if you have a plain text field in the datagrid. undo / redo functinality doesnt work once the cells focus is lost.
The end result is a very unplesent and unpredictable end user experience when they are trying to perform undo/redo operations. Anysuggestions on how this can easily be corrected?
Thanks
To use Undo/Redo operations, you have to implement the IEditableObject interface. Once the object is updated, you cannot revert to the old value. The XamDataGrid vol.9.2 offers undo/redo functionality. You can see samples in the XamFeatureBrowser - XamDataGrid - Layout and Behavior - Undo
I still have a few issues with this implementation.
1) Undo/redo only works "while the XamDataGrid has focus" once focus is lost, there is no way to undo within the datagrid.
2) If you do not have a complete multiple control undo stack implemented in your UI, then this implementation doesnt integrate well with the basic undo/redo functionality
3) There still remains no simplistic Undo/Redo that fits within the basic WPF behavior of undo/redo.
The end result is an inconsistent interface that must be overly documented and taught to your end users. Undo works like this... but if you are in a datagrid you can only.... etc...etc..... Then you get a dumb look from the end users and they ask "What is a data grid", and you know the solution is not going to be accepted.
Every text editor needs to have focus in order to redo/undo. For example, take the Office Word. The document always has focus, because the ribbon cannot take the focus and the document is always focused when you are pressing buttons in the ribbon. Keyboard combinations for redo/undo work when the document is on focus as well. You could probably implement a manager, which will save information on which was the last focused elements.
However, I am still confused about your requirement. You want the redo/undo to work when an element does not have focus. But, if an element does not have focus, this means that another element has it. So, you would have to provide logic for this as well - decide which elements should be able to redo/undo if they do not have focus and which elements should not redo/undo if they have.
as for the focus issue - I misunderstood what you were meaning when you stated "Once the object is updated, you cannot revert to the old value." I see how that is working now...
The requirement that we are trying to meet is simply have simple Undo/redo functionality capabilities within the XamDatagrid. (See above situation #1 and #2). right now undo redo will work in one of two manners - and neither is consistent with the basic WPF undo/redo functionality.
What we would like is basic undo redo functionality that fits within the paradigm exposed in a standard WPF form (undo redo within the edit control only). I can edit a text box, lose focusbox, then return to the text box and undo/redo still works. IE: We shouldnt have to 'reimplement' basic undo redo functionality that should already exist.
For Example - take your "Undo - Simple" feature sample.
1) Set focus into a Customer ID Cell and type something.
2) Press ctrl-Z ctrl-Y and see that undo/redo works.
3) Set focus on the undo Limit field
4) Edit the Undo Limit values, press ctrl-z (see that undo works), ctrl-y and see that redo DOES NOT work. (But leave it at this state for now)
5) regain focus on the customer ID cell. Press ctrl-Z ctrl-Y. basic Undo redo does not work
6) regain focus on Undo limit and edit the field to a different value - press ctrl-z twice. Notice that it goes back through the undo stack through the previous edit and back to original value (2 undos). press ctrl-y and notice it redo's back to the last edit (Skipping the intermediate value)
If you would implement a simple textbox in this UI, you would be able to lose and then regain focus on the textbox and undo/redo would work within the context of the control.
Also, look a tthe nuances that allowedit=true does to the xamcomboeditor controls undo redo functionality.
Does that make more sense.
I'm going to discuss a bit about the undo/redo and then if you still have questions I can try to answer then. There really is no "basic WPF behavior of undo/redo" - there is only an internal undo/redo implementation for the TextBox related classes that I believe attempts to mimic what the standard edit controls in the os provide.
With regards to our XamTextEditor, the EditTemplate contains a TextBox and that is what is used to edit the value when you are in edit mode. By default the control only enters edit mode while it has logical focus. Therefore when the control loses (logical) focus, the template reverts to the non-edit template and any undo that that textbox within the edit template instance is lost and when it regains focus, it will change its template to the edit template and it gets a new textbox. There is no way for us to prevent this or to access/transfer the undo history from the old textbox to the new one. You could set the IsAlwaysInEditMode to true so that it enters and never leaves edit mode.
With regards to the xamComboEditor, it itself has no undo/redo functionality. Even the intrinsic ComboBox has no undo/redo. The reason that you see some undo/redo when you set IsEditable is true because then the control contains a TextBox that receives focus when the combobox gets focus which allows you to either type in a value or select from the list. The undo/redo you see here is just that of the TextBox contained within the ComboBox's template while iseditable is true. The xamComboEditor currently contains a ComboBox in its edit template and therefore that combobox will only be around as long as it is in edit mode as I mentioned for xamTextEditor. Again you could set IsAlwaysInEditMode to true but as the ComboBox only supports some undo/redo while editable so will the xamComboEditor since it is just using a ComboBox for the editing.
With regards to undo/redo within the grid itself (added in 9.2), the functionality revolves around changes to the grid itself. The grid doesn't have any information/control over the editing/undo-redo within the cells themselves while they are in edit mode. When the cell exits edit mode and the value is committed, the grid stores an undo entry to restore the cell to its previous value. In this way it is exactly the same as excel. In Excel, the undo/redo you get while you remain in edit mode in a cell is just that of the textbox itself. When you leave that cell and go back, you don''t have any undo/redo for what you may have happened to enter when you were within that cell last time - you can just undo back through the undo/redo history to restore that cell back to its previous committed value (after undoing whatever other changes you made since that action). When you are not in a cell, the undo/redo is for the excel related actions (e.g. committing a value to a cell, resizing a column/row, etc.).