MvvmCross:MvxListView如何突出显示所选项目?

时间:2013-10-01 18:34:37

标签: c# android xamarin.android xamarin mvvmcross

我已经使用SelectedItem属性将数据绑定到我的ViewModel,每当我点击一个项目时,我都可以看到set方法触发。但是我在列表视图中点击的项目不会保持突出显示。知道为什么吗?

理想情况下,我也希望listview从选中的项目开始。但这也不起作用。我尝试过使用RaisePropertyChanged(()=> CurrentItem);在ViewModel构造函数中无济于事。

<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);
        }
    }

0 个答案:

没有答案