|
1 | | -# How-to-modify-or-disable-shortcuts-of-EditControl |
2 | | -This repository contains the sample that how to modify or disable shortcuts of EditControl. |
| 1 | +# How to Modify or Disable Shortcuts in WPF EditControl |
| 2 | +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. |
3 | 3 |
|
4 | | -The EditControl Undo and Redo functionality can be modify or disable by using the IsUndoEnabled and IsRedoEnabled property of Editcontrol. |
| 4 | +## Why This Is Useful |
| 5 | +- **Custom Behavior**: Implement your own shortcut logic. |
| 6 | +- **Restrict Actions**: Disable Undo/Redo in read-only or controlled environments. |
| 7 | +- **Dynamic Control**: Enable shortcuts only under specific conditions. |
5 | 8 |
|
6 | | -```C# |
7 | | -public Window1() |
8 | | -{ |
9 | | -Edit1.PreviewKeyDown += Edit1_PreviewKeyDown; |
10 | | -} |
11 | | -``` |
| 9 | +## Key Approaches |
| 10 | +1. Disable Undo and Redo using properties: |
| 11 | + - IsUndoEnabled = false |
| 12 | + - IsRedoEnabled = false |
| 13 | +2. Intercept keyboard shortcuts using PreviewKeyDown: |
| 14 | + - Apply conditional logic to enable or disable shortcuts dynamically. |
12 | 15 |
|
13 | | -You can also use our PreviewKeyDown event to modify this Undo and Redo features using the following code: |
| 16 | +## Code Example |
| 17 | +**XAML** |
| 18 | +```XAML |
| 19 | +<syncfusion:EditControl Name="Edit1" |
| 20 | + Grid.Row="2" |
| 21 | + AllowDrop="True" |
| 22 | + Background="White" |
| 23 | + BorderBrush="Black" |
| 24 | + BorderThickness="0" |
| 25 | + EnableOutlining="False" |
| 26 | + FontFamily="Verdana" |
| 27 | + Height="400" |
| 28 | + Width="400" /> |
| 29 | +``` |
14 | 30 |
|
| 31 | +**C#** |
15 | 32 | ```C# |
16 | | -private void Edit1_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) |
17 | | -{ |
18 | | -if(e.Key == Key.Z && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0) |
| 33 | + |
| 34 | +public partial class Window1 : Window |
19 | 35 | { |
20 | | -//Undo feature enable by checking the keys. |
21 | | -Edit1.IsUndoEnabled = true; |
22 | | -} |
| 36 | + public Window1() |
| 37 | + { |
| 38 | + SfSkinManager.SetTheme(this, new Theme("Office2019Colorful")); |
| 39 | + InitializeComponent(); |
| 40 | + |
| 41 | + Edit1.DocumentSource = @"../../Content.txt"; |
| 42 | + |
| 43 | + // Disable Undo and Redo |
| 44 | + Edit1.IsUndoEnabled = false; |
| 45 | + Edit1.IsRedoEnabled = false; |
| 46 | + |
| 47 | + // Uncomment to enable dynamic shortcut handling |
| 48 | + // Edit1.PreviewKeyDown += Edit1_PreviewKeyDown; |
| 49 | + } |
| 50 | + |
| 51 | + private void Edit1_PreviewKeyDown(object sender, KeyEventArgs e) |
| 52 | + { |
| 53 | + // Enable Undo only when Ctrl+Z is pressed |
| 54 | + if (e.Key == Key.Z && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0) |
| 55 | + { |
| 56 | + Edit1.IsUndoEnabled = true; |
| 57 | + } |
| 58 | + } |
23 | 59 | } |
24 | 60 | ``` |
25 | 61 |
|
| 62 | +## Notes |
| 63 | +- You can extend this logic to handle other shortcuts like Ctrl+Y, Ctrl+C, etc. |
| 64 | +- Use PreviewKeyDown for intercepting before default behavior executes. |
0 commit comments