sergevm
sergevm

Reputation: 353

Avalonia + ReactiveUI - pharmacist for Events() generation

I'm trying to get my head around Avalonia in general, and the Reactive UI integration in particular. From googling around, I understand that Avalonia pulled away the Avalonia support in ReactiveUI, and tries to integrate ReactiveUI into Avalonia itself, to support a sometimes unstable Avalonia API.

I'm implementing a flow where a double tap on a DataGrid row should open a details windows, which I can do by adding a handler for the DoubleTapped event in the code behind. However, I was wondering if I could do this in a Reactive UI way, in a WhenActivated() implementation, by observing the DoubleTapped event.

In the ReactiveUI documentation, I see that there is a Pharmacist integration, which generates the observables for these events. However, when I fetch a reference to the DataGrid in the code behind, and try to hook into the DoubleTapped via myDataGrid.Events(). ..., I don't get to see any events. Does this imply that there's no such support in Avalonia at this time?

Finally, while I'm at it, if I forget about the Reactive UI support, and use a straight-forward event handler, I need to do some stuff to detect whether it was a row that was double tapped, or something else (such as the header). I have to do this, because there's no EventSetter implementation in Avalonia as I understand it.

Somebody who knows if Avalonia will support this in the future?

Edit: in the end I used ReactiveUI somewhat similar to

TreeView.GetObservable(DoubleTappedEvent)
                .Subscribe(async x =>
                {
                    var selectedItem = TreeView.SelectedItem;
                    if (selectedItem is TreeNodeViewModel treeNodeViewModel)
                    {
                        await ViewModel!.ActivateResource(treeNodeViewModel);
                    }
                }).DisposeWith(d);

Upvotes: 0

Views: 1318

Answers (2)

Etienne Charland
Etienne Charland

Reputation: 4034

Pharmacist does not support Avalonia. They are working on ReactiveMarbles.ObservableEvents, which as of right now, doesn't work on generic classes, but they're working on fixing it.

Upvotes: 0

Pete Davis
Pete Davis

Reputation: 1137

An attached behaviour can also help to bind events to perform logic. There is a sample that looks like it could work provided the DoubleTappedEvent is being fired.

Avalonia Docs - Creating and binding Attached Properties

The dev tools should help show the event your are looking for tunnel and bubble though the DataGrid?

AvaloniaUI Dev tools showing the DoubleTapped event

Upvotes: 0

Related Questions