Ejemplo n.º 1
0
        private void Initialize()
        {
            _pagedViewModelPresenter = new PagedViewModelPresenter(Context);
            base.AddView(_pagedViewModelPresenter);

            _popupsPresenter = new PopupsPresenter(Context);

            base.AddView(_popupsPresenter);
        }
        public static View Convert(ViewGroup root, object value)
        {
            if (value == null)
            {
                return(null);
            }

            Type viewType;

            View view = null;

            if (ViewModelToViewMappings.TryGetValue(value.GetType(), out viewType))
            {
                view = CreateView(root, viewType);
            }

            else if (value is PagedViewModelWithPopups)
            {
                view = new PagedViewModelWithPopupsPresenter(root.Context);
            }

            else if (value is PagedViewModel)
            {
                view = new PagedViewModelPresenter(root.Context);
            }

            else
            {
                throw new NotImplementedException("ViewModel type was unknown: " + value.GetType());
            }

            // Get the ViewModel property
            var viewModelProperty = view.GetType().GetProperties().FirstOrDefault(p => p.Name.Equals("ViewModel"));

            if (viewModelProperty == null)
            {
                throw new InvalidOperationException("View must have a ViewModel property");
            }

            // And set the property
            viewModelProperty.SetValue(view, value);

            // And return the view
            return(view);
        }