question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Event-To-Command Behavior

See original GitHub issue

EventToCommandBehavior

  • 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:closed
  • Created 2 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
CliffAgiuscommented, Apr 14, 2022

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.

0reactions
bijingtoncommented, Apr 22, 2022

Done. Thanks @CliffAgius

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found