Category / Section
How to highlight the line color while saving the data as stream in WPF EditControl?
1 min read
You can update the line state after saving the data using our internal method (ChangeLinesState), which can be done by using the Reflection method in the WPF EditControl. Refer the code below for your reference.
C#
_editor.PreviewKeyUp += OnPreviewKeyUp; _editor.PreviewKeyDown += OnPreviewKeyDown; private void OnPreviewKeyUp(object sender, KeyEventArgs e) { switch (e.Key) { case Key.RightCtrl: case Key.LeftCtrl: _isCtrlDown = false; break; default: break; } } private void OnPreviewKeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.RightCtrl: case Key.LeftCtrl: _isCtrlDown = true; break; case Key.S: if (_isCtrlDown) { SetFileText(_editor.Text); e.Handled = true; } break; } } private void SetFileText(string text) { using (StreamWriter sw = new StreamWriter(_filePath)) { sw.Write(text); MethodInfo methodInfo = this._editor.GetType().GetMethod("ChangeLinesState", BindingFlags.NonPublic | BindingFlags.Instance); methodInfo?.Invoke(this._editor, new object[] { LineModificationState.Modified, LineModificationState.Saved}); } }
Output:
Sample: View sample in GitHub.