Hi there, everyone!
I have a simple listview on my Xamarin application which contains iterates over the menu items from an ObservableCollection:
<views:MenuItemsListView x:Name="_menuItemList"
ItemsSource="{Binding MenuItems}"
SelectedItem="{Binding SelectedMenuItem}"
SeparatorVisibility="None">
<ListView.Behaviors>
<behaviors:EventToCommandBehavior EventName="ItemTapped"
Command="{Binding NavigateCommand}" />
</ListView.Behaviors>
</views:MenuItemsListView>
- MenuItemsListView is a simple list view with a stackLayout and two labels.
On my ViewModel constructor, I'm inserting the available menus and updating the SelectedMenuItem in order to make the first item initially activated:
public MasterPageViewModel(INavigationService navigationService)
: base(navigationService)
{
MenuItems.Add(new MenuItemModel { Icon = "\ue88a", PageName = "HomePage", Title = "Início" });
MenuItems.Add(new MenuItemModel { Icon = "\ue7fd", PageName = "CustomersListPage", Title = "Clientes" });
MenuItems.Add(new MenuItemModel { Icon = "\ue871", PageName = "ProductsListPage", Title = "Produtos" });
MenuItems.Add(new MenuItemModel { Icon = "\ue8cc", PageName = "OrdersListPage", Title = "Pedidos" });
SelectedMenuItem = MenuItems[0];
MenuItems[0].IsSelected = true;
NavigateCommand = new DelegateCommand(HandleNavigate);
}
I can assure the SelectedMenuItem is being correctly updated. Basically, I'm using Prism's SetProperty to update the referenced _selectedMenuItem. For some odd reason, the background color of selected item is never updated (except when navigating, when it works accordingly).
I tried some solutions suggested here and there, but, as of now, none of them worked. I really appreciate if someone can help me with this!