ListItems in MvxListView bind inconsistently with Items in MvvmCross 6.4.1 after Upgrading

ε祈祈猫儿з 提交于 2019-12-11 06:02:42

问题


As the title indicates, I am in the process of upgrading the dependencies of an existing Xamarin.Android project. The Android project uses MvvmCross for much of the cross-platform code (we support other platforms as well). As part of this upgrade, we are moving from MvvmCross 6.2.2 to 6.4.1. We are currently building the app with Visual Studio 2019.

However, after upgrading, I have noticed that many of my project's layouts no longer bind under as consistently as they did when running. For many of our views on Android, we use MvxListView to render a list of form cells for the user to enter input. Under Mvx 6.2.2 built with Visual Studio 2017, the lists rendered as expected. However, when building with Visual Studio 2019 & Mvx 6.4.1 some items appeared to bind and others did not. I have ruled out Mvx 6.4.1 as the cause because I have tried compiling our app, unmodified, with both VS 2017 & 2019, and have still gotten inconsistent binding on VS 2019.

If if you guys have any suggestions on what to fix, I would love to hear it!

Some Android Build properties:

To illustrate what I mean by inconsistent binding:

Consistent binding:

Iconsistent Binding: Some snippets of code for the MvxAdapter subclass we use to render the individual rows:

private View _locationView;
        protected override View GetBindableView(View convertView, object source, ViewGroup parent, int templateId)
        {
            var item = source as ICellModel;
            if (item != null)
            {
                templateId = GetTemplateIdForCellType(item.CellType);
                templateId = GetStateCellForKey(item, templateId);
            }

            try
            {
                if (item != null && item.CellType != CellType.MapSelector)
                {
                    var bindableView = base.GetBindableView(convertView, source, parent, templateId);
                    return bindableView;
                }
                if (_locationView != null)
                {
                    return _locationView;
                }

                _locationView = base.GetBindableView(convertView, source, parent, templateId);
                return _locationView;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return null;
            }

        }

private int GetTemplateIdForCellType(CellType cellType)
        {
            // Example code to show picking a custom templace
            switch (cellType)
            {
                case CellType.X
                    return Resource.Layout.XCell;
                case CellType.Y:
                    return Resource.Layout.YCell;
                case CellType.Z:
                    return Resource.Layout.ZCell;
            }
            return -1;
        }

        private static int GetStateCellForKey(ICellModel cellModel, int templateId)
        {
            var singleLineEditCellsToBeDisplayCells = new List<int>
                {
                    .// Types for single line edit cells
                };
            var multiplineEditCellsToBeDisplayCells = new List<int>
            {
                // types for multi-line edit cells
            };
            if (cellModel.FormState == FormState.Display)
            {
                if (singleLineEditCellsToBeDisplayCells.Any(c => c.Equals(templateId)))
                    return Resource.Layout.SingleLineDisplayFormCell;
                else if (multiplineEditCellsToBeDisplayCells.Any(c => c.Equals(templateId)))
                    return Resource.Layout.MultiLineDisplayFormCell;
            }

            var selectorCellModel = cellModel as SelectorCellModel;
            if (selectorCellModel != null && selectorCellModel.IsMultiline)
            {
                return Resource.Layout.MultiLineSelectorCell;
            }


            //Multi line

            //Map cell
            return templateId;
        }

    }

来源:https://stackoverflow.com/questions/58668270/listitems-in-mvxlistview-bind-inconsistently-with-items-in-mvvmcross-6-4-1-after

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!