WindingConverter for Binding项目单击ListView模板MvvMCross

时间:2015-02-26 11:25:20

标签: android listview binding mvvmcross

我读过这个问题 Binding button click in ListView template MvvMCross 这是代码:

public class ListPresentationViewModel: MvxViewModel
    {
    private readonly ISQLService _sqlSvc;

    public ListPresentationViewModel (ISQLService sqlService)
    {
        _sqlSvc = sqlService;
        MenuCollection = WrapConverter.ConvertToWrapperClass(_sqlSvc.MenuItemGetAll (), this);
    }

    private List<MenuItemWrap> _menuCollection = new List<MenuItemWrap> ();
    public List<MenuItemWrap> MenuCollection {
        get{ return _menuCollection;}
        set {
            _menuCollection = value;
            RaisePropertyChanged (() => MenuCollection);
        }
    }

    private IMvxCommand _orderBtnClick;
    public IMvxCommand OrderBtnClick{
        get{
            _orderBtnClick = _orderBtnClick ?? new MvxCommand<MenuItemWrap> (btnClick);
            return _orderBtnClick;
        }
    }

    public void btnClick(MenuItemWrap item)
    {
        MenuCollection.Clear ();
    }
}

我想知道WrapConverter类。

是自定义还是标准库类?

感谢。

1 个答案:

答案 0 :(得分:0)

这是一个自定义类。此问题解释了此问题的原因:https://github.com/MvvmCross/MvvmCross/issues/35

使用包装器解决此问题的解释是:MVVMCross changing ViewModel within a MvxBindableListView

还有其他方法可以实现此行为:例如,使用包含列表的值转换器:How to binding list item to whether it is contained in another collection