public void ExecuteBackspaceCommand() { Debug.WriteLine("KeyboardViewModel.ExecuteBackspaceCommand"); if (TargetWindow != null) { #if !SILVERLIGHT ((Window)TargetWindow).Focus(); #endif TextBox txtTarget = TargetWindow.ControlToInjectInto as TextBox; if (txtTarget != null) { // Use the built-in Backspace command. Create it only once, and remove it when this VirtualKeyboard window is closing. //TODO #if !SILVERLIGHT if (_backspaceCommandBinding == null) { _backspaceCommandBinding = new CommandBinding(EditingCommands.Backspace); txtTarget.CommandBindings.Add(_backspaceCommandBinding); } _backspaceCommandBinding.Command.Execute(null); #endif MakeBackspaceSound(); // Perhaps I should return to the following code, if it will work in SL. ? // This was how I did the Backspace operation without using the command.. //int iCaretIndex = txtTarget.CaretIndex; //if (iCaretIndex > 0) //{ // string sOriginalContent = txtTarget.Text; // int nLength = sOriginalContent.Length; // if (iCaretIndex >= nLength) // { // txtTarget.Text = sOriginalContent.Substring(0, nLength - 1); // } // else // { // string sPartBeforeCaret = sOriginalContent.Substring(0, iCaretIndex - 1); // string sPartAfterCaret = sOriginalContent.Substring(iCaretIndex, nLength - iCaretIndex); // txtTarget.Text = sPartBeforeCaret + sPartAfterCaret; // } // txtTarget.CaretIndex = iCaretIndex - 1; //} } else // let's hope it's an IInjectableControl { IInjectableControl targetControl = TargetWindow.ControlToInjectInto as IInjectableControl; if (targetControl != null) { targetControl.Backspace(); MakeBackspaceSound(); } //else //{ // FsWpfControls.FsRichTextBox.FsRichTextBox txtrTarget = TargetWindow.ControlToInjectInto as FsWpfControls.FsRichTextBox.FsRichTextBox; // if (txtrTarget != null) // { // txtrTarget.InsertThis(chWhat.ToString()); // } } } //textbox.Text = sOriginalContent.Insert(iCaretIndex, sStuffToInsert); }