Skip to content

Commit 24576db

Browse files
authored
Merge pull request #1 from SyncfusionExamples/985360
985360: Updated ReadMe file
2 parents 7a0b139 + a52bf21 commit 24576db

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

README.md

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,64 @@
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.
33

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.
58

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.
1215

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+
```
1430

31+
**C#**
1532
```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
1935
{
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+
}
2359
}
2460
```
2561

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

Comments
 (0)