We use ReactiveUI and DynamicData and have two ListBoxes: ListBoxA and ListBoxB. Based on the selection of ListBoxA, the list in ListBoxB should be updated (Not filtered). Seems straightforward but I am having some trouble refreshing ListBoxB
The ListBoxes are bound like so in the View:
this.OneWayBind(ViewModel, vm => vm.ItemsA, v => v.ListBoxA.ItemsSource).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedItemA, v => v.ListBoxA.SelectedItem).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.ItemsB, v => v.ListBoxB.ItemsSource).DisposeWith(disposables);
ViewModel:=
_storage.PoolA.Connect()
.Transform(m => new ViewModelForA(m))
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out _itemsA)
.Subscribe();
SelectedItemA.PoolB.Connect()
.Transform(c => new ViewModelForB(c))
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out _itemsB)
.Subscribe();
Any help would be much appreciated!
Every time you select something in ListBoxA
your SelectedItemA
object changes and you need to recreate you connection to it.
At first we create an IObservable from SelectedItemA and then use Switch operator from DynamicData
class MyViewModel: INotifyPropertyChange
{
public MyViewModel()
{
_storage.PoolA.Connect()
...
this.WhenPropertyChanged(x => x.SelectedItemA)
.Select(x => x.Value.PoolB)
.Switch() // Switch from DynamicData
.Transform(c => new ViewModelForB(c))
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out _itemsB)
.Subscribe();
}
}