GLWpfControl icon indicating copy to clipboard operation
GLWpfControl copied to clipboard

Add support for commands as well as events.

Open mathew-odwyer opened this issue 2 years ago • 2 comments

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.

mathew-odwyer avatar Mar 25 '23 09:03 mathew-odwyer

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.

mathew-odwyer avatar Aug 11 '23 15:08 mathew-odwyer

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);
});

Xerxes004 avatar Jan 23 '24 16:01 Xerxes004