Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for commands as well as events. #107

Open
softwareantics opened this issue Mar 25, 2023 · 2 comments
Open

Add support for commands as well as events. #107

softwareantics opened this issue Mar 25, 2023 · 2 comments

Comments

@softwareantics
Copy link
Contributor

Description

I propose we add support for commands in the control and not just hook onto events. We can still keep the events for backwards compatibility.

The Why

This would allow users to further decouple their views from their models. It allows for easy integration into projects that use the MVVM design pattern.

The How

It's something I'll have to a little further into but from what I know it should be fairly straightforward; just add a few ICommand properties to the control and call the Execute function when they need to be executed.

@softwareantics
Copy link
Contributor Author

To be honest, thinking about this more - there is always EventBinder to accomplish this as a workaround. Happy to close if no one really wants this feature.

@Xerxes004
Copy link

This can be done easily with the Reactive Linq extensions, or ReactiveMarbles code generator libs.

// Reactive Linq extensions
using ReactiveUI;
using static System.Reactive.Linq.Observable;

<snip>

this.WhenActivated(d => {
    FromEvent<TimeSpan>(handler => GlWpfControl.Render += handler,
                        handler => GlWpfControl.Render -= handler)
        .WhereNotNull()
        .Select(_ =>Unit.Default)
        .InvokeCommand(ViewModel.DrawCmd)
        .DisposeWith(d);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants