© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
mario12136

❔ How to create commands for my subclassed AvalonEdit control?

Hello,

I am working on a WPF application, a notepad clone, and I am using AvalonEdit as the main editor. Basically I have some MenuItems that I would like to bind them to commands, such as selecting the current line in the editor or deleting it. I also want to create shortcuts for these MenuItems. AvalonEdit already comes with some pre-defined commands according to the doc. I also am not sure how to do this in a correct MVVM way, since I am not sure where to put these specific text editing commands. Most commands I use just have a [RelayCommand] on top of a function I defined, and the reason I am confused is because I wouldn't put these editing commands in the main view model since it shouldn't know about the AvalonEdit.

Scenario:
Just to illustrate further, there is a duplicate line MenuItem in the app's main menubar. Pressing Ctrl+L also duplicates the current line (if I don't want to click on the MenuItem).

Note:
I have already defined functions that carry out functionality like duplicating the line and I currently have in code-behind
...Click += TextEditor.DuplicateLine
...Click += TextEditor.DuplicateLine
...

My questions:
1. How can I create these commands that I want? Where do I define them exactly?
2. How can I bind to AvalonEdit's predefined commands, like the delete line comand?
3. Do I have to create dependency properties for these commands in my subclassed AvalonEdit?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How to create a bindable Text property for AvalonEdit?
C#CC# / help
3y ago
❔ How to use a readonly property for binding [AvalonEdit]?
C#CC# / help
3y ago
User Control Eventhandler. How to get my control's components to inherit an Eventhandler.
C#CC# / help
3y ago
❔ I want to create camera control with lerping
C#CC# / help
3y ago