2

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);
        }
    }
jokeane
  • 333
  • 3
  • 9
  • Does http://stackoverflow.com/questions/18364907/how-to-highlight-the-selected-item-in-an-mvxlistview/18409625#18409625 help? – Stuart Oct 01 '13 at 19:19
  • I will give the above work-around a try, although it would be nice to leverage the existing drawing code for displaying selection. Any idea why it doesn't work? – jokeane Oct 01 '13 at 21:37

0 Answers0