This ReactiveUserControl is inside a ListBoxItem. The ListBox is using virtualization. If I register the ShowDialogAsync on WhenActivated (*1) only the firsts UserControls are bound because virtualization recycles controls. Then, I should to bind using OnDataContextEndUpdate (*2). But this is not veri "reactive" way.
public class CentreRowUserCtrl : ReactiveUserControl<CentreRowViewModel>
{
public CentreRowUserCtrl()
{
InitializeComponent();
// (*1):
// this.WhenActivated(d =>
// d(ViewModel!.ShowDialog.RegisterHandler(ShowDialogAsync)));
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
protected override void OnDataContextEndUpdate()
{
base.OnDataContextBeginUpdate();
// (*2):
ViewModel?.ShowDialog.RegisterHandler(ShowDialogAsync);
}
How can I register with ReactiveUI in a virtualization context?