protected virtual void Awake() { if (DataProviderComponent != null && DataProviderComponent is IViewModelProvider provider) { DataProvider = provider; if (DataProvider.GetViewModel() != null) { IsDataReady = true; SetupBinding(); } else { DataProvider.DataReadyEvent += OnDataReady; } } else { DataProvider = GetComponentInParent <IViewModelProvider>(); if (DataProvider.GetViewModel() != null) { IsDataReady = true; SetupBinding(); } else { DataProvider.DataReadyEvent += OnDataReady; } } }
/// <summary> /// Constructor /// </summary> /// <param name="models">List of models to synch with</param> /// <param name="viewModelProvider"></param> /// <param name="context"></param> /// <param name="autoFetch"> /// Determines whether the collection of ViewModels should be /// fetched from the model collection on construction /// </param> public VmCollection(ICollection <TModel> models, IViewModelProvider <TViewModel, TModel> viewModelProvider, object context = null, bool autoFetch = true) { _models = models; _context = context; _viewModelProvider = viewModelProvider; // Register change handling for synchronization // from ViewModels to Models CollectionChanged += ViewModelCollectionChanged; // If model collection is observable register change // handling for synchronization from Models to ViewModels if (models is ObservableCollection <TModel> ) { var observableModels = models as ObservableCollection <TModel>; observableModels.CollectionChanged += ModelCollectionChanged; } // Fecth ViewModels if (autoFetch) { FetchFromModels(); } }
private void DisposeInternal() { //Disposing commands, if need. if (Settings.DisposeCommands) { ReflectionExtensions.DisposeCommands(this); } ClearBusy(); ClearPropertyChangedSubscribers(); var toRemove = _viewModelEventAggregator.GetObservers(); for (int index = 0; index < toRemove.Count; index++) { Unsubscribe(toRemove[index]); } IViewManager viewManager; if (IocContainer.TryGet(out viewManager)) { viewManager.CleanupViewAsync(this); } _viewModelProvider = null; //Disposing ioc adapter. if (Settings.DisposeIocContainer && _iocContainer != null) { _iocContainer.Dispose(); } _disposeCancellationToken.Cancel(); Tracer.TraceViewModel(AuditAction.Disposed, this); Settings.Metadata.Clear(); }
public static IViewModel GetViewModel([NotNull] this IViewModelProvider viewModelProvider, [NotNull] Type viewModelType, params DataConstantValue[] parameters) { Should.NotBeNull(viewModelProvider, nameof(viewModelProvider)); Should.NotBeNull(viewModelType, nameof(viewModelType)); return(viewModelProvider.GetViewModel(viewModelType, new DataContext(parameters))); }
public NavigationProvider([NotNull] INavigationService navigationService, [NotNull] IThreadManager threadManager, [NotNull] IViewMappingProvider mappingProvider, [NotNull] IViewManager viewManager, [NotNull] IViewModelProvider viewModelProvider, [NotNull] INavigationDispatcher navigationDispatcher, IEventAggregator eventAggregator) { Should.NotBeNull(navigationService, nameof(navigationService)); Should.NotBeNull(threadManager, nameof(threadManager)); Should.NotBeNull(mappingProvider, nameof(mappingProvider)); Should.NotBeNull(viewManager, nameof(viewManager)); Should.NotBeNull(viewModelProvider, nameof(viewModelProvider)); Should.NotBeNull(navigationDispatcher, nameof(navigationDispatcher)); Should.NotBeNull(eventAggregator, nameof(eventAggregator)); NavigationService = navigationService; ThreadManager = threadManager; ViewMappingProvider = mappingProvider; ViewManager = viewManager; ViewModelProvider = viewModelProvider; NavigationDispatcher = navigationDispatcher; _vmReference = Empty.WeakReference; NavigationService.Navigating += NavigationServiceOnNavigating; NavigationService.Navigated += NavigationServiceOnNavigated; eventAggregator.Subscribe(this); #if WINDOWS_UWP _openedViewModels = new Dictionary <Guid, IViewModel>(); #endif }
public static T GetViewModel <T>([NotNull] this IViewModelProvider viewModelProvider, IViewModel parentViewModel = null, ObservationMode?observationMode = null, IocContainerCreationMode?containerCreationMode = null, params DataConstantValue[] parameters) where T : IViewModel { return(GetViewModel <T>(viewModelProvider, MergeParameters(parentViewModel, containerCreationMode, observationMode, parameters))); }
void Start() { if (textField == null) { textField = GetComponent <Text>(); } if (textTemplate == null || textTemplate.Length == 0) { textTemplate = textField.text; } if (!Application.isPlaying) { return; } if (viewModelSource == null) { viewModelProvider = GetComponentInParent <IViewModelProvider>(); } if (viewModelProvider == null && (viewModelProvider = viewModelSource.GetComponent <IViewModelProvider>()) == null) { Debug.LogError($"IViewModelProvider has not been found in {viewModelSource}"); } }
public QueryTabContentViewModel(ILog log, IViewModelProvider viewModelProvider) : base(log) { _viewModelProvider = viewModelProvider; var defaultQueryParam = viewModelProvider.Instantiate <QueryParameterViewModel>(); QueryParams.Add(defaultQueryParam); }
public SplitViewViewModelPresenter(IViewModelProvider viewModelProvider, INavigationDispatcher navigationDispatcher, IOperationCallbackManager callbackManager) { _viewModelProvider = viewModelProvider; _navigationDispatcher = navigationDispatcher; _callbackManager = callbackManager; viewModelProvider.Preserved += OnViewModelPreserved; viewModelProvider.Restored += OnViewModelRestored; }
public NewDaySheetViewModel(IViewModelProvider viewModelProvider, IPlannerViewModel parentViewModel, IDaySummaryViewModel selectedDay) { _timeAvailable = selectedDay.TimeSpent; _timeSpent = selectedDay.TimeSpent; _tasks = selectedDay.Tasks; _viewModelProvider = viewModelProvider; _parentViewModel = parentViewModel; }
public NewDaySheetViewModel(IViewModelProvider viewModelProvider, IPlannerViewModel parentViewModel, DateTime date, string timeAvailable, string timeSpent, List <ITaskViewModel> tasks) { _timeAvailable = timeSpent; _timeSpent = timeSpent; _tasks = new ObservableCollection <ITaskViewModel>(tasks); _viewModelProvider = viewModelProvider; _parentViewModel = parentViewModel; }
public static IViewModel GetViewModel([NotNull] this IViewModelProvider viewModelProvider, [NotNull, ViewModelTypeRequired] Type viewModelType, IViewModel parentViewModel = null, ObservationMode?observationMode = null, IocContainerCreationMode?containerCreationMode = null, params DataConstantValue[] parameters) { return(GetViewModel(viewModelProvider, viewModelType, MergeParameters(parentViewModel, containerCreationMode, observationMode, parameters))); }
public static IViewModel GetViewModel([NotNull] this IViewModelProvider viewModelProvider, [NotNull] GetViewModelDelegate <IViewModel> getViewModel, IViewModel parentViewModel = null, ObservationMode?observationMode = null, IocContainerCreationMode?containerCreationMode = null, params DataConstantValue[] parameters) { return(GetViewModel(viewModelProvider, getViewModel, MergeParameters(parentViewModel, containerCreationMode, observationMode, parameters))); }
public static T GetViewModel <T>([NotNull] this IViewModelProvider viewModelProvider, [NotNull] GetViewModelDelegate <T> getViewModelGeneric, params DataConstantValue[] parameters) where T : IViewModel { Should.NotBeNull(viewModelProvider, "viewModelProvider"); Should.NotBeNull(getViewModelGeneric, "getViewModelGeneric"); return((T)viewModelProvider.GetViewModel(adapter => getViewModelGeneric(adapter), new DataContext(parameters))); }
public static T GetViewModel <T>([NotNull] this IViewModelProvider viewModelProvider, [NotNull] GetViewModelDelegate <T> getViewModelGeneric, params DataConstantValue[] parameters) where T : class, IViewModel { Should.NotBeNull(viewModelProvider, nameof(viewModelProvider)); Should.NotBeNull(getViewModelGeneric, nameof(getViewModelGeneric)); return((T)viewModelProvider.GetViewModel(getViewModelGeneric, new DataContext(parameters))); }
public void Initialize() { _contextModelFactory = new ContextViewModelFactory(); _runtimeFactories = new List <IViewModelProvider>(); //register context provider as first _runtimeFactories.Add(_contextModelFactory); _runtimeFactories.AddRange(modelProviders.Select(x => x.Value)); }
public static void Unload([NotNull, UsedImplicitly] this IViewModelProvider provider, [NotNull] ViewModelBase viewModel) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } ((IViewModelProviderConnectionTarget)viewModel).Unload(); }
public PlotterViewModel(IViewModelProvider viewModelProvider, IModelProvider modelProvider) { _viewModelProvider = viewModelProvider; _modelProvider = modelProvider; Nodes = new ObservableCollection <INodeViewModel> { _viewModelProvider.GetNodeViewModel(_modelProvider.GetNode(0, 0)) }; }
public FrameNavigationService(Frame frame, IViewModelProvider viewModelProvider) { Should.NotBeNull(frame, nameof(frame)); Should.NotBeNull(viewModelProvider, nameof(viewModelProvider)); _frame = frame; _viewModelProvider = viewModelProvider; _frame.Navigating += OnNavigating; _frame.Navigated += OnNavigated; }
public DayCRUDViewModel(IViewModelProvider viewModelProvider, IPlannerViewModel parent, IDaySummaryViewModel selectedDay) { _viewModelProvider = viewModelProvider; _date = selectedDay.DisplayDate; _timeAvailable = selectedDay.TimeAvailable; _timeSpent = selectedDay.TimeSpent; _tasks = selectedDay.Tasks; _parent = parent; }
public MainViewModel(ILog log, IFitsDatabaseService fitsDatabaseService, IViewModelProvider viewModelProvider) : base(log) { _fitsDatabaseService = fitsDatabaseService; _viewModelProvider = viewModelProvider; // Name = "Hello"; // QueryTabs.Add(_viewModelProvider.Instantiate<QueryTabContainerViewModel>()); }
private static void OnViewModelPreserved(IViewModelProvider sender, ViewModelPreservedEventArgs args) { var mainViewModel = args.ViewModel as MainViewModel; if (mainViewModel?.SelectedItem != null) { args.State.AddOrUpdate(SelectedItemState, sender.PreserveViewModel(mainViewModel.SelectedItem, DataContext.Empty)); } }
public RestorableViewModelPresenter(INavigationDispatcher navigationDispatcher, IViewModelProvider viewModelProvider, ISerializer serializer) : base(navigationDispatcher) { Should.NotBeNull(viewModelProvider, nameof(viewModelProvider)); _viewModelProvider = viewModelProvider; _serializer = serializer; _openedViewModels = new List <IViewModel>(); GetStateDictionary = () => Application.Current.Properties; }
public ViewModelFactory( IViewModelProvider<TViewModel, TArg> viewModelProvider, IViewModelProviderArgumentsProvider argumentsProvider, IPrerequisitesChecker prerequisitesChecker ) { _viewModelProvider = viewModelProvider; _argumentsProvider = argumentsProvider; _prerequisitesChecker = prerequisitesChecker; }
public void Setup() { _viewModelProvider = MockRepository.GenerateMock<IViewModelProvider<TestViewModel, TestViewModelProviderArgument>>(); _viewModelProviderArgumentsProvider = MockRepository.GenerateMock<IViewModelProviderArgumentsProvider>(); _prerequisitesChecker = MockRepository.GenerateMock<IPrerequisitesChecker>(); _viewModelFactory = new ViewModelFactory<TestViewModel, TestViewModelProviderArgument>( _viewModelProvider, _viewModelProviderArgumentsProvider, _prerequisitesChecker ); }
/// <summary> /// 当类型实现了 <see cref="IViewModelProvider"/> 接口后,通过此扩展方法 /// 将 <see cref="ViewModelBase"/> 关联到此 <see cref="IViewModelProvider"/>。 /// <para/> /// 这样,<see cref="ViewModelBase"/> 将可以向 <see cref="IViewModelProvider"/> /// 发送它与其他 View 和 ViewModel 的通信请求。 /// </summary> /// <param name="provider"><see cref="IViewModelProvider"/> 接口的实例。</param> /// <param name="viewModel">被 <paramref name="provider"/> 管理的 <see cref="ViewModelBase"/>。</param> /// <exception cref="ArgumentNullException"> /// 参数 <paramref name="provider"/> 或 <paramref name="viewModel"/> 为 null。 /// </exception> public static void Connect([NotNull] this IViewModelProvider provider, [NotNull] ViewModelBase viewModel) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } ((IViewModelProviderConnectionTarget)viewModel).Provider = provider ?? throw new ArgumentNullException(nameof(provider)); }
public void Startup(ILogService logging, IViewModelProvider modelProvider) { Startup(logging, modelProvider.Environment); Main = modelProvider.Main; RegisterViewModel(Main); Exemplary = modelProvider.Exemplary; RegisterViewModel(Exemplary); }
public void Setup() { _viewModelProvider = MockRepository.GenerateMock <IViewModelProvider <TestViewModel, TestViewModelProviderArgument> >(); _viewModelProviderArgumentsProvider = MockRepository.GenerateMock <IViewModelProviderArgumentsProvider>(); _prerequisitesChecker = MockRepository.GenerateMock <IPrerequisitesChecker>(); _viewModelFactory = new ViewModelFactory <TestViewModel, TestViewModelProviderArgument>( _viewModelProvider, _viewModelProviderArgumentsProvider, _prerequisitesChecker); }
public DaySummaryViewModel(IViewModelProvider viewModelProvider, IDaySummary daySummary) { _viewModelProvider = viewModelProvider; _date = daySummary.Date; _displayDate = _date.Date.ToShortDateString(); _timeAvailable = daySummary.TimeAvailable; _timeSpent = daySummary.TimeSpent; _tasks = new ObservableCollection <ITaskViewModel>(_viewModelProvider.GetTaskModels(daySummary.Tasks)); _isToday = Date == DateTime.Now.Date; }
public ModalViewMediator([NotNull] IThreadManager threadManager, [NotNull] IViewManager viewManager, [NotNull] IWrapperManager wrapperManager, [NotNull] IViewMappingProvider viewMappingProvider, [NotNull] IViewModelProvider viewModelProvider, [NotNull] INavigationDispatcher navigationDispatcher, [NotNull] IEventAggregator eventAggregator) : base(threadManager, viewManager, wrapperManager, navigationDispatcher, eventAggregator) { Should.NotBeNull(viewMappingProvider, nameof(viewMappingProvider)); Should.NotBeNull(viewModelProvider, nameof(viewModelProvider)); _viewMappingProvider = viewMappingProvider; _viewModelProvider = viewModelProvider; UseAnimations = true; }
public static bool TryGetViewModel(Type viewType, out object viewModelInstance) { Guard.ArgumentNotNull(viewType, "viewType"); // we get the provider and then get the instance IViewModelProvider _viewModelProvider = null; var _response = ResourceLocator.TryGetResource <IViewModelProvider>(viewType.FullName, out _viewModelProvider); viewModelInstance = _viewModelProvider == null ? null : _viewModelProvider.CreateViewModelInstance(); return(_response); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationStateManager" /> class. /// </summary> public ApplicationStateManager([NotNull] ISerializer serializer, [NotNull] IViewModelProvider viewModelProvider, [NotNull] IViewManager viewManager, [NotNull] IViewModelPresenter viewModelPresenter) { Should.NotBeNull(serializer, "serializer"); Should.NotBeNull(viewModelProvider, "viewModelProvider"); Should.NotBeNull(viewManager, "viewManager"); Should.NotBeNull(viewModelPresenter, "viewModelPresenter"); _serializer = serializer; _viewModelProvider = viewModelProvider; _viewManager = viewManager; _viewModelPresenter = viewModelPresenter; }
public WrapperManagerEx(IViewModelProvider viewModelProvider) : base(viewModelProvider) { }
/// <summary> /// Initializes a new instance of the <see cref="NavigationProvider" /> class. /// </summary> public NavigationProvider([NotNull] INavigationService navigationService, [NotNull] IThreadManager threadManager, [NotNull] IViewMappingProvider mappingProvider, [NotNull] IViewManager viewManager, [NotNull] IViewModelProvider viewModelProvider, IOperationCallbackManager callbackManager, INavigationCachePolicy cachePolicy = null) { Should.NotBeNull(navigationService, "navigationService"); Should.NotBeNull(threadManager, "threadManager"); Should.NotBeNull(mappingProvider, "mappingProvider"); Should.NotBeNull(viewManager, "viewManager"); Should.NotBeNull(viewModelProvider, "viewModelProvider"); Should.NotBeNull(callbackManager, "callbackManager"); _navigationService = navigationService; _threadManager = threadManager; _mappingProvider = mappingProvider; _viewManager = viewManager; _viewModelProvider = viewModelProvider; _callbackManager = callbackManager; _cachePolicy = cachePolicy; _vmReference = Empty.WeakReference; _closeViewModelHandler = CloseableViewModelOnClosed; NavigationService.Navigating += NavigationServiceOnNavigating; NavigationService.Navigated += NavigationServiceOnNavigated; }