Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 55 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,64 @@
# How-to-modify-or-disable-shortcuts-of-EditControl
This repository contains the sample that how to modify or disable shortcuts of EditControl.
# How to Modify or Disable Shortcuts in WPF EditControl
This example demonstrates how to disable or modify keyboard shortcuts in the Syncfusion WPF EditControl. By default, EditControl supports common shortcuts like Undo (Ctrl+Z) and Redo (Ctrl+Y). In some scenarios, you may want to override or disable these shortcuts to implement custom logic or restrict user actions.

The EditControl Undo and Redo functionality can be modify or disable by using the IsUndoEnabled and IsRedoEnabled property of Editcontrol.
## Why This Is Useful
- **Custom Behavior**: Implement your own shortcut logic.
- **Restrict Actions**: Disable Undo/Redo in read-only or controlled environments.
- **Dynamic Control**: Enable shortcuts only under specific conditions.

```C#
public Window1()
{
Edit1.PreviewKeyDown += Edit1_PreviewKeyDown;
}
```
## Key Approaches
1. Disable Undo and Redo using properties:
- IsUndoEnabled = false
- IsRedoEnabled = false
2. Intercept keyboard shortcuts using PreviewKeyDown:
- Apply conditional logic to enable or disable shortcuts dynamically.

You can also use our PreviewKeyDown event to modify this Undo and Redo features using the following code:
## Code Example
**XAML**
```XAML
<syncfusion:EditControl Name="Edit1"
Grid.Row="2"
AllowDrop="True"
Background="White"
BorderBrush="Black"
BorderThickness="0"
EnableOutlining="False"
FontFamily="Verdana"
Height="400"
Width="400" />
```

**C#**
```C#
private void Edit1_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if(e.Key == Key.Z && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0)

public partial class Window1 : Window
{
//Undo feature enable by checking the keys.
Edit1.IsUndoEnabled = true;
}
public Window1()
{
SfSkinManager.SetTheme(this, new Theme("Office2019Colorful"));
InitializeComponent();

Edit1.DocumentSource = @"../../Content.txt";

// Disable Undo and Redo
Edit1.IsUndoEnabled = false;
Edit1.IsRedoEnabled = false;

// Uncomment to enable dynamic shortcut handling
// Edit1.PreviewKeyDown += Edit1_PreviewKeyDown;
}

private void Edit1_PreviewKeyDown(object sender, KeyEventArgs e)
{
// Enable Undo only when Ctrl+Z is pressed
if (e.Key == Key.Z && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0)
{
Edit1.IsUndoEnabled = true;
}
}
}
```

## Notes
- You can extend this logic to handle other shortcuts like Ctrl+Y, Ctrl+C, etc.
- Use PreviewKeyDown for intercepting before default behavior executes.