17
votes

I have an Outlook addin (VSTO), on an Outlook form region I have a WPF user control within an ElementHost. I have an issue that a TextBox within my user control does not have the undo capability... in some configurations. Specifically in Windows 7 / Outlook 2007 undo (ie Ctrl-Z) does not work, even though Cut/Copy etc all do work. Interestingly Windows 8 / Outlook 2010 undo does work.

The TextBox XAML is:

<TextBox 
    Name="txtnote" 
    VerticalScrollBarVisibility="Auto" 
    SpellCheck.IsEnabled="True"  
    Text="Topic notes..." 
    TextWrapping="Wrap" 
    AcceptsReturn="True" />

Note: I have tried setting the following attributes to make it work but to no avail: IsUndoEnabled="True" UndoLimit="-1"

Can anyone suggest why this is happening and what I can do to make it work as expected?

UPDATE 7 Jan 2014. I have added the following KeyBindings to the text box:

<TextBox.InputBindings>
    <KeyBinding Command="ApplicationCommands.Undo" Key="Z" Modifiers="Control" />
    <KeyBinding Command="ApplicationCommands.Redo" Key="Y" Modifiers="Control" />
    <KeyBinding Command="ApplicationCommands.Undo" Key="G" Modifiers="Alt" />
</TextBox.InputBindings>

And the result is - Cntl-Z/Cntrl-Y still does not work, however Alt-G does work!

2
Thats odd, something in the plumbing must have changed. Excel intercepts all keyboard input from non-Excel child windows in its process. Out of curiosity does undo'ing after programmatically pasting work?Clipboard.SetText("Undo me"); TextBox.Paste();Jeremy Thompson
Hi Jeremy - thanks for that. No, undoing (ie press Cntl-Z) after a programmatic paste does not work. However I also tried to do the undo from the undo stack, and that does work. ie: if (txtnote.CanUndo == true) {txtnote.Undo();} else { MessageBox.Show("Can't Undo");}Marcin
Sp it seems that the Control-Z/Control-Y is being hijacked somewhere.Marcin
This is reflected in the fact that the KeyBinding for the TextBox does not work for Control-Z/Y, yet does for an Alt-G binding for undo.Marcin
What happens if you set UndoLimit=-1 in the Xaml?Gayot Fow

2 Answers

1
votes

Plugins are not allowed to handle core Excel shortcuts. Probably due to that, shortcuts are not working.

0
votes

Try notifying the windows that the current control's (textbox) value has been changed, maybe on text-changed event as below. (not tried it, but had applied to my control in a similar scenario, where the controls was not able to identify the modification)

Method library............

[DllImport("user32.dll", EntryPoint = "SendMessageW", SetLastError = true)]
public static extern IntPtr SendMessageW([InAttribute] IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr lParam);

//Current handle for textBox

IntPtr _handle

//Sets or clears the modification flag for an edit control. The modification flag indicates whether the text within the edit control has been modified. You can send this message to either an edit control or a rich edit control.

int SETMODIFY = 185,//0x00B9 (constant)

//On text change

SendMessageW(_handle, new IntPtr(SETMODIFY), IntPtr.Zero, IntPtr.Zero);