public void ProviderShouldBindIocContainerBindIocContainerTrue()
        {
            Type   typeFrom     = null;
            object item         = null;
            string name         = null;
            var    iocContainer = new IocContainerMock
            {
                BindToConstantFunc = (type, arg2, arg3) =>
                {
                    typeFrom = type;
                    item     = arg2;
                    name     = arg3;
                }
            };
            ViewModelProvider provider = GetViewModelProvider(iocContainer);

            provider.BindIocContainer = true;
            var context = new DataContext();

            IViewModel viewModel = provider.GetViewModel(container => new ViewModel(), context);

            typeFrom.ShouldEqual(typeof(IIocContainer));
            item.ShouldEqual(viewModel.IocContainer);
            name.ShouldBeNull();
        }
        public void GetViewModelShouldUseIocContainerToCreateViewModel()
        {
            var context    = new DataContext();
            int initialize = 0;
            var vm         = new ViewModel
            {
                InitializeViewModel = dataContext =>
                {
                    dataContext.ShouldEqual(context);
                    ++initialize;
                }
            };
            var iocContainer = new IocContainerMock
            {
                GetFunc = (type, s, arg3) =>
                {
                    type.ShouldEqual(typeof(ViewModel));
                    return(vm);
                }
            };

            ViewModelProvider provider  = GetViewModelProvider(iocContainer);
            IViewModel        viewModel = provider.GetViewModel(typeof(ViewModel), context);

            viewModel.ShouldEqual(vm);
            initialize.ShouldEqual(1);
        }
        protected override void OnAppearing()
        {
            CommonActions.OnNavigateToPage += CommonActions_OnNavigateToPage;
            var vm = ViewModelProvider.GetViewModel <MainPageViewModel>();

            vm.RefreshChildren();
            base.OnAppearing();
        }
示例#4
0
        public async Task PushAsync <TViewModel>(Action <TViewModel> customInit = null)
            where TViewModel : ViewModelBase, new()
        {
            var viewmodel = ViewModelProvider.GetViewModel <TViewModel>(customInit);

            // TODO: Throw new custom exception if unable to create VM?

            if (viewmodel != null)
            {
                await PushAsync(viewmodel);
            }
        }
示例#5
0
        public App()
        {
            InitializeComponent();

            DependencyService.Register <IReportingService, ReportingService>();
            DependencyService.Register <ViewProvider>();

            RegisterViews();

            var viewProvider = DependencyService.Get <ViewProvider>();

            MainPage = new NavigationPage(viewProvider.GetView(ViewModelProvider.GetViewModel <CalendarsViewModel>()) as Page);
        }
        public MainPage()
        {
            //Initialize UI
            InitializeComponent();
            BindingContext            = ViewModelProvider.GetViewModel <MainPageViewModel>();
            this.ToolbarItems[0].Icon = ImageSource.FromFile("start.png") as FileImageSource;
            this.ToolbarItems[1].Icon = ImageSource.FromFile("stop.png") as FileImageSource;
            this.ToolbarItems[2].Icon = ImageSource.FromFile("testnow.png") as FileImageSource;

            _logPage   = new LogPage();
            _chartPage = new ChartPage();

            Children.Add(_chartPage);
            Children.Add(_logPage);
        }
        public void WhenInitialazingVmShouldUseObservationModeFromApplicationSettingsNotSpecifiedExplicitly()
        {
            ApplicationSettings.ViewModelObservationMode = ObservationMode.Both;
            var iocContainer           = new IocContainerMock();
            ViewModelProvider provider = GetViewModelProvider(iocContainer);
            var parentViewModel        = new ViewModel();
            var context = new DataContext
            {
                { InitializationConstants.ParentViewModel, parentViewModel }
            };

            var viewModel = (ViewModel)provider.GetViewModel(container => new ViewModel(), context);

            parentViewModel.LocalEventAggregator.GetObservers().Contains(viewModel).ShouldBeTrue();
            viewModel.LocalEventAggregator.GetObservers().Contains(parentViewModel).ShouldBeTrue();
        }
        public void WhenInitialazingVmShouldUseObservationModeFromDataContextModeBoth()
        {
            const ObservationMode mode = ObservationMode.Both;
            var iocContainer           = new IocContainerMock();
            ViewModelProvider provider = GetViewModelProvider(iocContainer);
            var parentViewModel        = new ViewModel();
            var context = new DataContext
            {
                { InitializationConstants.ObservationMode, mode },
                { InitializationConstants.ParentViewModel, parentViewModel }
            };

            var viewModel = (ViewModel)provider.GetViewModel(container => new ViewModel(), context);

            parentViewModel.LocalEventAggregator.GetObservers().Contains(viewModel).ShouldBeTrue();
            viewModel.LocalEventAggregator.GetObservers().Contains(parentViewModel).ShouldBeTrue();
        }
        public void ProviderShouldUseObservationModeFromDataContextModeNone()
        {
            const ObservationMode mode = ObservationMode.None;
            var iocContainer           = new IocContainerMock();
            ViewModelProvider provider = GetViewModelProvider(iocContainer);
            var parentViewModel        = new ViewModel();
            var context = new DataContext
            {
                { InitializationConstants.ObservationMode, mode },
                { InitializationConstants.ParentViewModel, parentViewModel }
            };

            var viewModel = (ViewModel)provider.GetViewModel(container => new ViewModel(), context);

            viewModel.ViewModelEventAggregator.GetObservers().Contains(viewModel).ShouldBeFalse();
            viewModel.ViewModelEventAggregator.GetObservers().Contains(viewModel).ShouldBeFalse();
        }
        public void ProviderShouldNotBindIocContainerBindIocContainerFalse()
        {
            bool isInvoked    = false;
            var  iocContainer = new IocContainerMock
            {
                BindToConstantFunc = (type, arg2, arg3) =>
                {
                    isInvoked = true;
                }
            };
            ViewModelProvider provider = GetViewModelProvider(iocContainer);

            provider.BindIocContainer = false;
            var context = new DataContext();

            IViewModel viewModel = provider.GetViewModel(container => new ViewModel(), context);

            isInvoked.ShouldBeFalse();
        }
        public void GetViewModelShouldUseDelegateToCreateViewModel()
        {
            var iocContainer           = new IocContainerMock();
            ViewModelProvider provider = GetViewModelProvider(iocContainer);
            var context = new DataContext();

            int initialize = 0;
            var vm         = new ViewModel
            {
                InitializeViewModel = dataContext =>
                {
                    dataContext.ShouldEqual(context);
                    ++initialize;
                }
            };
            IViewModel viewModel = provider.GetViewModel(container => vm, context);

            viewModel.ShouldEqual(vm);
            initialize.ShouldEqual(1);
        }
        public SettingsPage()
        {
            //Initialize UI
            InitializeComponent();
            //there are a lot of binding bugs in XForms yet, so using this workarounds
            _vm            = ViewModelProvider.GetViewModel <SettingsViewModel>();
            BindingContext = _vm;
            urlRadioGroup.CheckedChanged += urlRadioGroup_CheckedChanged;
            checkPicker.Items.Clear();
            checkPicker.Items.Add("30 Seconds");
            checkPicker.Items.Add("1 Minute");
            checkPicker.Items.Add("5 Minutes");
            checkPicker.Items.Add("10 Minutes");
            checkPicker.Items.Add("30 Minutes");
            checkPicker.Items.Add("1 Hour");

            checkPicker.SelectedIndex         = _vm.CheckConnectionTime;
            checkPicker.SelectedIndexChanged += checkPicker_SelectedIndexChanged;

            dateRadioGroup.CheckedChanged  += dateRadioGroup_CheckedChanged;
            speedRadioGroup.CheckedChanged += speedRadioGroup_CheckedChanged;
        }
        public void GetViewModelShouldUseIocContainerToCreateViewModelWithParameters()
        {
            var          parameters = new IIocParameter[0];
            const string vmName     = "vmName";
            int          initialize = 0;

            var context = new DataContext
            {
                { InitializationConstants.ViewModelBindingName, vmName },
                { InitializationConstants.IocParameters, parameters }
            };
            var vm = new ViewModel
            {
                InitializeViewModel = dataContext =>
                {
                    dataContext.ShouldEqual(context);
                    ++initialize;
                }
            };
            var iocContainer = new IocContainerMock
            {
                GetFunc = (type, s, arg3) =>
                {
                    s.ShouldEqual(vmName);
                    arg3.ShouldEqual(parameters);
                    type.ShouldEqual(typeof(ViewModel));
                    return(vm);
                }
            };

            ViewModelProvider provider  = GetViewModelProvider(iocContainer);
            IViewModel        viewModel = provider.GetViewModel(typeof(ViewModel), context);

            viewModel.ShouldEqual(vm);
            initialize.ShouldEqual(1);
        }
示例#14
0
 protected internal T GetViewModel <T>(ObservationMode?observationMode = null, params DataConstantValue[] parameters) where T : IViewModel
 {
     return(ViewModelProvider.GetViewModel <T>(this, observationMode, parameters));
 }
示例#15
0
 protected internal T GetViewModel <T>([NotNull] GetViewModelDelegate <T> getViewModelGeneric, ObservationMode?observationMode = null,
                                       params DataConstantValue[] parameters) where T : class, IViewModel
 {
     return(ViewModelProvider.GetViewModel(getViewModelGeneric, this, observationMode, parameters));
 }
示例#16
0
 protected internal IViewModel GetViewModel([NotNull] Type viewModelType, ObservationMode?observationMode = null, params DataConstantValue[] parameters)
 {
     return(ViewModelProvider.GetViewModel(viewModelType, this, observationMode, parameters));
 }
示例#17
0
 /// <summary>
 ///     Creates an instance of the specified view model.
 /// </summary>
 /// <param name="getViewModel">The specified delegate to create view model.</param>
 /// <param name="containerCreationMode">The value that is responsible to initialize the IocContainer.</param>
 /// <param name="observationMode">The value that is responsible for listen messages in created view model.</param>
 /// <param name="parameters">The specified parameters to get view-model.</param>
 /// <returns>
 ///     An instance of <see cref="IViewModel" />.
 /// </returns>
 protected internal IViewModel GetViewModel([NotNull] GetViewModelDelegate <IViewModel> getViewModel, ObservationMode?observationMode = null,
                                            IocContainerCreationMode?containerCreationMode = null, params DataConstantValue[] parameters)
 {
     EnsureNotDisposed();
     return(ViewModelProvider.GetViewModel(getViewModel, this, observationMode, containerCreationMode, parameters));
 }
示例#18
0
 protected internal IViewModel GetViewModel([NotNull] GetViewModelDelegate <IViewModel> getViewModel, ObservationMode?observationMode = null,
                                            params DataConstantValue[] parameters)
 {
     return(ViewModelProvider.GetViewModel(getViewModel, this, observationMode, parameters));
 }
 public SimpleSamplePage()
 {
     InitializeComponent();
     BindingContext = ViewModelProvider.GetViewModel <SimpleSampleViewModel>();
 }
示例#20
0
 /// <summary>
 ///     Creates an instance of the specified view model.
 /// </summary>
 /// <param name="viewModelType">The type of view model.</param>
 /// <param name="containerCreationMode">The value that is responsible to initialize the IocContainer.</param>
 /// <param name="observationMode">The value that is responsible for listen messages in created view model.</param>
 /// <param name="parameters">The specified parameters to get view-model.</param>
 /// <returns>
 ///     An instance of <see cref="IViewModel" />.
 /// </returns>
 protected internal IViewModel GetViewModel([NotNull, ViewModelTypeRequired] Type viewModelType, ObservationMode?observationMode = null,
                                            IocContainerCreationMode?containerCreationMode = null, params DataConstantValue[] parameters)
 {
     EnsureNotDisposed();
     return(ViewModelProvider.GetViewModel(viewModelType, this, observationMode, containerCreationMode, parameters));
 }
示例#21
0
 /// <summary>
 ///     Creates an instance of the specified view model.
 /// </summary>
 /// <typeparam name="T">The type of view model.</typeparam>
 /// <param name="containerCreationMode">The value that is responsible to initialize the IocContainer.</param>
 /// <param name="observationMode">The value that is responsible for listen messages in created view model.</param>
 /// <param name="parameters">The specified parameters to get view-model.</param>
 /// <returns>
 ///     An instance of <see cref="IViewModel" />.
 /// </returns>
 protected internal T GetViewModel <T>(ObservationMode?observationMode = null,
                                       IocContainerCreationMode?containerCreationMode = null, params DataConstantValue[] parameters) where T : IViewModel
 {
     EnsureNotDisposed();
     return(ViewModelProvider.GetViewModel <T>(this, observationMode, containerCreationMode, parameters));
 }
 /// <summary>
 /// Set datacontex of this page to specific ViewModel instance
 /// </summary>
 /// <typeparam name="T">ViewModel</typeparam>
 public void SetViewModel <T>() where T : BaseViewModel
 {
     BindingContext = ViewModelProvider.GetViewModel <T>();
 }
 public ViewModel GetViewModel(string viewModelName, string persistenceModelName = null)
 {
     return(ViewModelProvider.GetViewModel(viewModelName, GetPersistenceModel(persistenceModelName)));
 }