Behaviors
The Editor
control has a number of events. These can be handled by event handlers in the code-behind file, but for the reasons already explained (and explained) we’d rather not do that. So, here enters behaviors.
Behaviors let you add functionality to your controls without having to create subclasses. They tack on the behavior. What we want to do now is tack on the ability to manage commands in a control (Editor
) that doesn’t have commands.
The .NET MAUI Community Toolkit comes with a plethora of behaviors, including EventToCommandBehavior
. This wonderful behavior allows you to transform an event (which would be handled in the code-behind file) into a command, which can be handled in ViewModel
.
The event we want to change in Editor
is OnEditorCompleted
, which is raised when the user hits the Enter key (or, on Windows, the Tab key):
<Editor FontSize="Small" HeightRequest="300"...