I've used the SelectedItem property for data-binding to my ViewModel, and whenever I tap on an item I can see that set method firing. But the item I tapped in the listview doesn't stay highlighted. Any idea why?
Ideally I'd also like the listview to start out with that item selected. But that isn't working either. I've tried using RaisePropertyChanged(() => CurrentItem); in the ViewModel constructor to no avail.
<Mvx.MvxListView
android:id="@+id/mainListView"
android:layout_width="240dp"
android:layout_height="fill_parent"
local:MvxItemTemplate="@layout/mainListItem"
local:MvxBind="ItemsSource Items; SelectedItem CurrentItem; ItemClick ShowDetailCommand" />
/// <summary>
/// Gets or sets the selected item.
/// </summary>
/// <value>The selected item.</value>
public MainListItem CurrentItem
{
get
{
if (SelectedIndex >= 0 && SelectedIndex < MainItems.Count)
{
return MainItems[SelectedIndex];
}
return null;
}
set
{
if (value != null)
{
int idx = MainItems.FindIndex(info => info.Name == value.Name);
if (SelectedIndex != idx)
{
SelectedIndex = idx;
}
}
else
{
SelectedIndex = -1;
}
RaisePropertyChanged(() => CurrentItem);
}
}