public DeredundafierMockTree() { var parent = new DeredundafierDTO() { Name = "Test 1 - None Checked" }; parent.Children.Add(new SelectorDTO() { IsChecked = false }); parent.Children.Add(new SelectorDTO() { IsChecked = false }); ViewModels.Add(new PotentialMatchViewModel(parent)); (ViewModels.Last() as PotentialMatchViewModel).ReevaluateColor(); parent = new DeredundafierDTO() { Name = "Test 2 - Mixed Checks" }; var child = new SelectorDTO() { Name = "SubTest 1", IsChecked = true }; child.Children.Add(new DeredundafierDTO()); parent.Children.Add(child); child = new SelectorDTO() { Name = "SubTest 2", IsChecked = false }; child.Children.Add(new DeredundafierDTO()); parent.Children.Add(child); ViewModels.Add(new PotentialMatchViewModel(parent) { IsExpanded = true }); (ViewModels.Last() as PotentialMatchViewModel).ReevaluateColor(); parent = new DeredundafierDTO() { Name = "Test 3 - All Checked" }; parent.Children.Add(new SelectorDTO() { IsChecked = true }); parent.Children.Add(new SelectorDTO() { IsChecked = true }); ViewModels.Add(new PotentialMatchViewModel(parent)); (ViewModels.Last() as PotentialMatchViewModel).ReevaluateColor(); }
private void ChangeViewModel(Type viewModelType) { if (!typeof(IViewModel).IsAssignableFrom(viewModelType)) { throw new ArgumentException("Not a valid view model type"); } //check if already on this viewModelType if (viewModelType.IsAssignableFrom(this.currentViewModel?.GetType())) { return; } //check if viewModelType already in memory var viewModelFromMemory = ViewModels.Where(v => v.GetType() == viewModelType).FirstOrDefault(); if (viewModelFromMemory == null) { //get new viewmodel; viewModelFromMemory = GetViewViewModel(viewModelType); //add to memory ViewModels.Add(viewModelFromMemory); } this.currentViewModel = viewModelFromMemory; }
private void ChangeViewModel(IViewModel viewModel) { if (!ViewModels.Contains(viewModel)) { ViewModels.Add(viewModel); } // Check if new ViewModel is Login if (ViewModels.IndexOf(viewModel) == 0) { _history.Clear(); Mediator.Mediator.Notify("ClearLogin", ""); Mediator.Mediator.Notify("SessionID", new System.Guid("00000000-0000-0000-0000-000000000000")); CurrentViewModel = ViewModels.FirstOrDefault(vm => vm == viewModel); return; } // Check if new ViewModel is Home if (ViewModels.IndexOf(viewModel) == 2) { _history.Clear(); Mediator.Mediator.Notify("SetHome", "Hidden"); } else { Mediator.Mediator.Notify("SetHome", "Visible"); } CurrentViewModel = ViewModels.FirstOrDefault(vm => vm == viewModel); }
public AppViewModel(List <CalcCore.CalcAssembly> calcs, List <PluginInfo> plugins) { Assemblies = calcs; _plugins = plugins; CalcCore.ICalc calcInstance = (CalcCore.ICalc)Activator.CreateInstance(Assemblies[1].Class); ViewModels.Add(new CalculationViewModel(calcInstance, _plugins)); }
private void AddCommandExecute() { AddButtonVisibility = Visibility.Hidden; var addCityControlViewModelBase = ContainerHelper.Resolve <IAddCityControlViewModel>(new { mainWindowViewModel = this }) as ViewModelBase; ViewModels.Add(addCityControlViewModelBase); }
public MainViewmodel() { ChangeToBoekViewCommand = new ExecuteCommand(OnBookClick); ChangeToAuteurViewCommand = new ExecuteCommand(OnAuteurClick); ViewModels.Add("boek", new BoekViewModel()); ViewModels.Add("auteur", new AuteurViewModel()); }
/// <summary> /// If the ViewModel, identified by the combination of the event arguments, not already exists in the ViewModels list, /// then a new Viewmodel (NavigationViewModel or DetailViewModel) is created from the event arguments, /// and LoadAsync function of the created ViewModel is called /// and ViewModel is added tio ViewModels list /// and SelectedViewModel is set to ViewModel. /// </summary> /// <param name="eventOpenViewModelArgs">Id and Name of the ViewModel</param> private async void OnEventOpenNavigationOrDetailViewModel(EventOpenNavigationOrDetailViewModelArgs eventOpenViewModelArgs) { IsBusy = true; var viewModel = ViewModels.SingleOrDefault(dvm => dvm.Id == eventOpenViewModelArgs.Id && dvm.Name == eventOpenViewModelArgs.ViewModelName); //ViewModel does not exist in ViewModels //-> create, call ViewModels LoadAsync function and add ViewModel to ViewModels if (viewModel == null) { viewModel = _viewModelFactory.Create(eventOpenViewModelArgs.ViewModelName); bool loadAsyncSucessful = await viewModel.LoadAsync(eventOpenViewModelArgs.Id); //bool loadAsyncSucessful = await Task.Run(() => viewModel.LoadAsync(eventOpenViewModelArgs.Id)); if (loadAsyncSucessful) { ViewModels.Add(viewModel); //Set the focus to the selected ViewModel SelectedViewModel = viewModel; //Hide the MainNavigationView: IsMainNavigationViewShown = false; } else { _messageDialogService.ShowInfoDialog("Entry could not be loaded as it might have been deleted. Displayed Entries are refreshed.", "Information"); } } IsBusy = false; }
public MainViewModel() { _history = new Stack <int>(); // Add available pages and set page ViewModels.Add(new LoginViewModel()); ViewModels.Add(new HomeViewModel()); ViewModels.Add(new RegisterViewModel()); ViewModels.Add(new MovieViewModel()); ViewModels.Add(new PaymentViewModel()); ViewModels.Add(new AboutUsViewModel()); ViewModels.Add(new UserManagementViewModel()); ViewModels.Add(new MovieManagementViewModel()); ViewModels.Add(new SettingsViewModel()); ViewModels.Add(new ShoppingCartViewModel()); ViewModels.Add(new PaymentConfirmationViewModel()); CurrentViewModel = ViewModels[0]; Mediator.Mediator.Subscribe("GoToHome", this.OnGoToHome); Mediator.Mediator.Subscribe("GoToLogin", this.OnLogin); Mediator.Mediator.Subscribe("GoToRegister", this.OnRegister); Mediator.Mediator.Subscribe("GoToMovie", this.OnGoToMovie); Mediator.Mediator.Subscribe("GoToPayment", this.OnGoToPayment); Mediator.Mediator.Subscribe("GoToAboutUs", this.OnGoToAboutUs); Mediator.Mediator.Subscribe("GoToMovieManagement", this.OnGoToMovieManagement); Mediator.Mediator.Subscribe("GoToUserManagement", this.OnGoToUserManagement); Mediator.Mediator.Subscribe("GoToSettings", this.OnGoToSettings); Mediator.Mediator.Subscribe("GoToShoppingCart", this.OnGoToShoppingCart); Mediator.Mediator.Subscribe("GoToPaymentConfirmation", this.OnGoToPaymentConfirmation); Mediator.Mediator.Subscribe("GoBack", this.OnGoBack); }
public ModelDefinition MergeModelDefinitions(IEnumerable <ModelDefinition> modelDefinitions) { IEnumerable <PropertyDefinition> commonPropertyDefinitions = new List <PropertyDefinition>(); commonPropertyDefinitions = modelDefinitions.FirstOrDefault()?.PropertyDefinitions; foreach (var modelDefinition in modelDefinitions.Skip(1)) { commonPropertyDefinitions = commonPropertyDefinitions.Intersect(modelDefinition.PropertyDefinitions); if (!commonPropertyDefinitions.Any()) { break; } } ModelDefinition mergedModelDefinition = new ModelDefinition() { Purpose = modelDefinitions.FirstOrDefault().Purpose, TypeName = string.Join("", modelDefinitions.Take(3).Select(md => md.TypeName)) + "Base", Title = string.Join("", modelDefinitions.Take(3).Select(md => md.Title)) + "Base", TcmUri = "dynamic-" + dynamicModelCounter++, PropertyDefinitions = commonPropertyDefinitions.ToList() }; ViewModels.Add(mergedModelDefinition); return(mergedModelDefinition); }
/// <summary> /// Gets the view model with the given type, creating it if necessary /// </summary> /// <typeparam name="T">Type of the desired view model</typeparam> /// <param name="appViewModel">Instance of the current application ViewModel</param> /// <returns>The requested view model, or null if it does not exist</returns> public T GetViewModel <T>(ApplicationViewModel appViewModel) where T : GenericViewModel { var currentViewModels = GetViewModels(appViewModel); var desired = currentViewModels.FirstOrDefault(x => x is T); if (desired != null) { return(desired as T); } else { var newInstance = CurrentPluginManager.CreateInstance(typeof(T)) as GenericViewModel; if (newInstance.SupportsObject(Model)) { newInstance.SetApplicationViewModel(appViewModel); newInstance.SetModel(Model); ViewModels.Add(newInstance); RegisterViewModelEventHandlers(newInstance); return(newInstance as T); } else { return(null); } } }
public void ChangePage <TViewModel>() where TViewModel : IViewModel, new() { // If we are already on the same page as the button click, we don't change anything if (AppWindow.ViewModel.CurrentViewModel == null || AppWindow.ViewModel.CurrentViewModel.GetType() != typeof(TViewModel)) { foreach (IViewModel viewModel in ViewModels) { // If an instance of the viewmodel already exists, we switch to that one if (viewModel.GetType() == typeof(TViewModel)) { AppWindow.ViewModel.CurrentViewModel = viewModel; return; } } // Else, we create a new instance of the viewmodel TViewModel newViewModel; if (_container != null) { newViewModel = _container.Resolve <TViewModel>(); } else { newViewModel = new TViewModel(); } AppWindow.ViewModel.CurrentViewModel = newViewModel; ViewModels.Add(newViewModel); } }
public static T GetViewModel <T>() where T : ObservableViewModel, new() { if (ViewModels == null) { ViewModels = new Dictionary <string, ObservableViewModel>(); } var name = typeof(T).Name; if (ViewModels.ContainsKey(name)) { try { return((T)ViewModels[name]); } catch { ViewModels[name] = new T(); FileStore.DeleteAsync(AppData.VMDictionary).ContinueOn(); return((T)ViewModels[name]); } } else { var obj = new T(); obj.OnInit(); ViewModels.Add(name, obj); return(obj); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); for (int i = 0; i < 200; i++) { ViewModels.Add(GetRandomViewModel()); } }
//#region Fields //private IViewModel _currentViewModel; //private List<IViewModel> _viewModels; //private ICommand _changeViewCommand; //private int indexOfCurrentViewModel; //#endregion public MainViewModel() { ViewModels.Add(new OverviewViewModel()); ViewModels.Add(new OrderViewModel()); ViewModels.Add(new DataUpdateViewModel()); CurrentViewModel = ViewModels[0]; CurrentViewModel.ChangeViewCommandIsEnable = false; }
private void ChangeViewModel(object viewModel) { if (!ViewModels.Contains(viewModel)) { ViewModels.Add(viewModel); } CurrentViewModel = ViewModels.FirstOrDefault(vm => vm == viewModel); }
public void Add(T item) { ViewModels.Add(item); if (CanAddToView(item)) { View.Add(item); } }
void IStrategy.Inject(object viewModel, Type viewType) { if (viewModel == null || ViewModels.Contains(viewModel)) { return; } ViewSelector.Add(viewModel, viewType); ViewModels.Add(viewModel); OnInjected(viewModel); }
public VMMainWindow() { ViewModels.Add(ViewModelSource.Create(() => new VMUsers())); ViewModels.Add(ViewModelSource.Create(() => new VMPersons())); ViewModels.Add(ViewModelSource.Create(() => new VMGroups())); ViewModels.Add(ViewModelSource.Create(() => new VMSystemConstants())); SelectedViewModel = ViewModels.FirstOrDefault(); SelectedViewModel.ViewModelButtonColor = new BrushConverter().ConvertFromString(Values.SystemValues.MyColors.Selected) as Brush; }
private void AddViewModelsToCollection() { ViewModels.Add(new CloseGameViewModel()); ViewModels.Add(new DiceViewModel()); ViewModels.Add(new GameBoardViewModel()); ViewModels.Add(new PlayerCreationViewModel()); GetViewModel <PlayerCreationViewModel>().SetInitials(); ViewModels.Add(new StartingRollViewModel()); ViewModels.Add(new StartScreenViewModel()); }
public void Inject(object viewModel, string viewName, Type viewType) { if (viewModel == null || ViewModels.Contains(viewModel)) { return; } CheckInjectionProcedure(viewModel, viewName, viewType); ViewModelInfos.Add(viewModel, viewName, viewType); ViewModels.Add(viewModel); OnInjected(viewModel); }
public DataUpdateViewModel() { Name = "Data Update"; ViewModels.Add(new CustomerViewModel()); ViewModels.Add(new StoreViewModel()); ViewModels.Add(new CustomerRankViewModel()); ViewModels.Add(new CategoryViewModel()); ViewModels.Add(new ProductViewModel()); ViewModels.Add(new GoodsReceiptViewModel()); CurrentViewModel = ViewModels[0]; CurrentViewModel.ChangeViewCommandIsEnable = false; }
private void DoAddPreset() { PresetViewModel pvm = new PresetViewModel(); foreach (PresetViewModel p in ViewModels) { p.IsSelected = false; } ViewModels.Add(pvm); pvm.IsSelected = true; OnPropertyChanged("ViewModels"); OnPropertyChanged("SelectedViewModel"); }
/// <inheritdoc /> public override void Show() { Update(); GUILayout.Box("Base ship stats", BoxStyle); if (GUILayout.Button("Add")) { ViewModels.Add(CreateNewView(Utils.ShipStatsDataPath)); } foreach (var viewModel in ViewModels) { ShowViewModel(viewModel); } }
/// <inheritdoc /> public void Add(TViewModel item) { if (ViewModels.Contains(item) || EncapsulatedList.Any(i => ReferenceEquals(i, item?.Model))) { throw new NotSupportedException("The item was already added to the collection"); } ViewModels.Add(item); EncapsulatedList.Add(item?.Model); CollectionChanged?.Invoke(ViewModels, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item)); OnAllPropertiesChanged(); ClearItemCsommand.OnCanExecuteChanged(); RemoveItemCommand.OnCanExecuteChanged(); }
public PrivateTagMockTree() { ViewModels.Add(new PrivateTagViewModel(new PrivateTagDTO { Owner = "Test1/Test" })); ViewModels.Add(new PrivateTagViewModel(new PrivateTagDTO { Owner = "Test1/OtherTest" })); ViewModels.Add(new PrivateTagViewModel(new PrivateTagDTO { Owner = "Test1/OtherOtherTest" })); ViewModels.Add(new PrivateTagViewModel(new PrivateTagDTO { Owner = "Test2/Test2" })); }
/// <inheritdoc /> public override void Show() { Update(); GUILayout.Box("Levels Manager", BoxStyle); if (GUILayout.Button("Add")) { ViewModels.Add(CreateNewView(Utils.LevelsDataPath)); } foreach (var viewModel in ViewModels) { ShowViewModel(viewModel, viewModel.Model.Name); } }
public void Select(Preset preset) { if (preset == null) { throw new ArgumentNullException("preset", "Cannot select PresetViewModel without Preset"); } PresetViewModel pvm = ViewModels.FirstOrDefault(p => p.IsViewModelOf(preset)); if (pvm == null) { pvm = new PresetViewModel(preset); ViewModels.Add(pvm); } pvm.IsSelected = true; }
private void ChangeViewModel(IViewModel viewModel) { if (!ViewModels.Contains(viewModel)) { ViewModels.Add(viewModel); } // Check if new ViewModel is Login if (ViewModels.IndexOf(viewModel) == 0) { _history.Clear(); Mediator.Mediator.Notify("ClearLogin", ""); CurrentViewModel = ViewModels.FirstOrDefault(vm => vm == viewModel); return; } // Check if new ViewModel is Home if (ViewModels.IndexOf(viewModel) == 1) { _history.Clear(); Mediator.Mediator.Notify("SetHome", "Hidden"); Mediator.Mediator.Notify("RefreshHome", ""); } else { Mediator.Mediator.Notify("SetHome", "Visible"); } if (ViewModels.IndexOf(viewModel) == 6) { Mediator.Mediator.Notify("RefreshUserManagement", ""); } else if (ViewModels.IndexOf(viewModel) == 7) { Mediator.Mediator.Notify("RefreshMovieManagement", ""); } else if (ViewModels.IndexOf(viewModel) == 9) { Mediator.Mediator.Notify("RefreshShoppingCart", ""); } else if (ViewModels.IndexOf(viewModel) == 10) { _history.Clear(); Mediator.Mediator.Notify("SetHome", "Hidden"); } CurrentViewModel = ViewModels.FirstOrDefault(vm => vm == viewModel); }
public TViewModel RegisterViewModel <TViewModel>(string vmKey) where TViewModel : ViewModelBase, new() { TViewModel rst; string typekey = GetViewModelKey(typeof(TViewModel), vmKey); if (ViewModels.ContainsKey(typekey)) { rst = ViewModels[typekey] as TViewModel; } else { rst = new TViewModel(); ViewModels.Add(typekey, rst); } return(rst); }
/// <summary> /// Sets up the navigation, and makes the viewmodels and commands. /// </summary> public MainViewModel() { //All viewmodels are made here. When new are made remember to add them here. MenuViewModel menuVM = new MenuViewModel(); SoloGameViewModel soloGameVM = new SoloGameViewModel(); //All viewmodels are added to the list. When new are made remember to add them here. ViewModels.Add(menuVM); ViewModels.Add(soloGameVM); //Commands to change between the viewmodels. When new are made remember to add them here. ViewSoloGameCommand = new RelayCommand(p => CurrentViewModel = soloGameVM); ViewMenuCommand = new RelayCommand(p => CurrentViewModel = menuVM); //Decides the viewmodel we start on. CurrentViewModel = menuVM; }