I have a basic list of elements displaying a name. I need to go to a new screen when I click on one of the list items. Super simple, right? I can not understand where this is happening.
The list displays its items correctly. After selecting an item in the form of a list, the corresponding item is selected, but nothing else happens. I have no mistakes. It looks like the view model and view are not connected properly or perhaps the subscription in the view model is not configured properly. I am very new to ReactiveUI.
Below are dummy examples of my code.
ItemListViewModel.cs
public IReactiveDerivedList<ItemTileViewModel> ItemTiles { get; protected set; } public ItemTileViewModel SelectedItemTile { get; set; } private void Initialize(){ ItemTiles = LoadedItems.CreateDerivedCollection(item => new ItemTileViewModel(item)); this.WhenAnyValue(x => x.SelectedItemTile) .Where(tile => tile != null) .Select(tile => tile.Model) .Subscribe(item => { HostScreen.Router.Navigate.ExecuteAsync(new ItemViewModel(item)); SelectedItemTile = null; });
I'm not sure if using a derived list is correct. I expect that I will not give sufficient context for feedback on this.
ItemListView.xaml.cs - contructor
this.OneWayBind(ViewModel, vm => vm.ItemTiles, v => v.ItemTiles.ItemsSource); this.Bind(ViewModel, vm => vm.SelectedItemTile, v => v.ItemTiles.SelectedItem);
ItemListView.xaml
<ListView x:Name="ItemTiles"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <views:ItemTileView ViewModel="{Binding}" /> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>
source share