Example #1
0
        // TODO YP: export to base, looks the same as Android impl.
        protected virtual Type GetTargetViewType(Type viewModelType)
        {
            if (_viewModelToViewMap.TryGetValue(viewModelType, out var targetViewType))
            {
                return(targetViewType);
            }

            var targetTypeName = BuildViewTypeName(viewModelType);

            targetViewType = Type.GetType(targetTypeName) ! ?? AssemblySource.FindTypeByNames(new[] { targetTypeName }) !;

            if (targetViewType == null)
            {
                throw new InvalidOperationException($"Can't find target view type: {targetTypeName}");
            }

            return(targetViewType);
        }
Example #2
0
        public void NavigateTo(BaseVM viewModel, Func <BaseVM, bool> afterViewClosed = null)
        {
            if (afterViewClosed != null)
            {
                viewModel.AfterViewClosed = afterViewClosed;
            }

            if (ViewModelToViewMap.TryGetValue(viewModel.GetType(), out Type viewType))
            {
                var view = Activator.CreateInstance(viewType) as BaseView;
                view.ViewModel = viewModel;

                views.Push(view);

                if (Region != null)
                {
                    Region.Content     = view;
                    Region.DataContext = viewModel;
                }
            }
        }