[Proposal] Event-To-Command Behavior
See original GitHub issueEventToCommandBehavior
- Proposed
- Prototype
- Implementation
- iOS Support
- Android Support
- macOS Support
- Windows Support
- Unit Tests
- Documentation
- Sample
Summary
The EventToCommandBehavior
is a Behavior
that allows the user to invoke an ICommand
through an Event
. It is designed to associate ICommand
to events exposed by controls that were not designed to support Commands. It allows you to map any arbitrary event on a control to an ICommand
.
Detailed Design
public class EventToCommandBehavior : BaseBehavior<VisualElement>
{
public static readonly BindableProperty EventNameProperty;
public static readonly BindableProperty CommandProperty;
public static readonly BindableProperty CommandParameterProperty;
public static readonly BindableProperty EventArgsConverterProperty;
public string? EventName { get; set; }
public ICommand? Command { get; set; }
public object? CommandParameter { get; set; }
public IValueConverter EventArgsConverter { get; set; }
}
Usage Syntax
XAML Usage
<Button.Behaviors>
<toolkit:EventToCommandBehavior
EventName="Clicked"
Command="{Binding MyCustomCommand}" />
</Button.Behaviors>
C# Usage
var button = new Button();
button.Behaviors.Add(new EventToCommandBehavior
{
EventName = nameof(Button.Clicked),
Command = new MyCustomCommand()
});
Drawbacks
Alternatives
Unresolved Questions
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (9 by maintainers)
Top Results From Across the Web
event-to-command-behavior.md
The EventToCommandBehavior is a behavior that allows the user to invoke a Command through an event. It is designed to associate Commands to...
Read more >Use the EventToCommand Behavior to Execute ...
The EventToCommand behavior allows you to bind an event to a command. When used, the bound command is invoked like an event handler...
Read more >EventToCommandBehavior - .NET MAUI Community Toolkit
The EventToCommandBehavior is a behavior that allows the user to invoke a Command through an event. It is designed to associate Commands to ......
Read more >Add EventToCommand behavior in codebehind
Hello,. How can I create behavior EventToCommand in codebehind? In my case I want to register this behavior in my CustomUserControl.
Read more >Xamarin Community Toolkit EventToCommandBehavior
It allows you to map any arbitrary event on a control to a Command. Syntax. This behavior can be used on any control...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @IndianaGary don’t worry we all have busy times and projects to complete. I’m between projects at the moment so will pick this one up.
Done. Thanks @CliffAgius