public Animal CreateAnimal(BindableBase mainContext, ICategory baseContext) { MainViewModel context = (MainViewModel)mainContext; Animal animal = null; switch (context.SelectedSpecies) { case Species.Raccoon: animal = new Raccoon( context.Name, int.Parse(context.Age), context.Gender, ((MammalViewModel)(baseContext)).IsDomesticated, ((RaccoonViewModel)(baseContext.SelectedSpeciesControl)).Type); break; case Species.Donkey: animal = new Donkey( context.Name, int.Parse(context.Age), context.Gender, ((MammalViewModel)(baseContext)).IsDomesticated, int.Parse(((DonkeyViewModel)(baseContext.SelectedSpeciesControl)).Stubbornness)); break; } return(animal); }
string IDataErrorInfo.this[string columnName] { get { string NazwaProp = BindableBase.GetPropertyName(() => Nazwa); string NipProp = BindableBase.GetPropertyName(() => Nip); string EmailProp = BindableBase.GetPropertyName(() => Email); string TelkomProp = BindableBase.GetPropertyName(() => Telkom); if (columnName == NazwaProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(NazwaProp, Nazwa)); } if (columnName == NipProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(NipProp, Nip)); } if (columnName == EmailProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(EmailProp, Email)); } if (columnName == TelkomProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(TelkomProp, Telkom)); } else { return(null); } } }
private string AddUndoOnFULLCODEChanges(COMMODITY_CODE entity) { string newValue = GenerateFullCode(entity); EntitiesUndoRedoManager.AddUndo(entity, BindableBase.GetPropertyName(() => new COMMODITY_CODE().FULLCODE), entity.FULLCODE, newValue, EntityMessageType.Changed); return(newValue); }
public static string Validate(this BindableBase vm, string propertyName) { if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentException("Invalid property name", propertyName); } string error = string.Empty; var value = vm.GetType().GetProperty(propertyName).GetValue(vm); var results = new List <ValidationResult>(1); var result = Validator.TryValidateProperty( value, new ValidationContext(vm, null, null) { MemberName = propertyName }, results); if (!result) { var validationResult = results.First(); error = validationResult.ErrorMessage; } return(error); }
private IEnumerable <COMMODITY_CODE> ReorderAndSave(Guid guid_parent, bool dontSave = false) { IEnumerable <COMMODITY_CODE> childCommodityCodes = this.Entities.Where(x => x.GUID_PARENT == guid_parent).OrderBy(x => x.SORTORDER).ToList(); int commodityCodeOrderCount = 10; foreach (COMMODITY_CODE childCommodityCode in childCommodityCodes) { if (childCommodityCode.SORTORDER != commodityCodeOrderCount) { EntitiesUndoRedoManager.AddUndo(childCommodityCode, BindableBase.GetPropertyName(() => new COMMODITY_CODE().SORTORDER), childCommodityCode.SORTORDER, commodityCodeOrderCount, EntityMessageType.Changed); childCommodityCode.SORTORDER = commodityCodeOrderCount; int tryParseInt; if (childCommodityCode.CODE == "temp") { childCommodityCode.CODE = GenerateOrderString(childCommodityCode.SORTORDER); } else { childCommodityCode.CODE = Int32.TryParse(childCommodityCode.CODE, out tryParseInt) ? AddUndoOnCODEChanges(childCommodityCode, GenerateOrderString(childCommodityCode.SORTORDER)) : childCommodityCode.CODE; } } commodityCodeOrderCount += 10; } RecurseRenameChildrenFULLCODE(guid_parent); if (!dontSave) { this.BulkSave(childCommodityCodes); } return(childCommodityCodes); }
/// <summary>Invokes the ChangeCanExecute of all commands of the target VM. /// </summary> /// <param name="target">The target.</param> public static void InvokeChangeCanExecute(this BindableBase target) { if (target != null) { var commands = target.GetType() // Only the public ICommand properties are of interest. The private's // can never be visible in XAML. Moreover, the private's are probably // the backing fields only. .GetProperties(BindingFlags.Public | BindingFlags.Instance) // Get only the properties of type ICommand. .Where(pi => pi.PropertyType == typeof(System.Windows.Input.ICommand)) // Determine the ChangeCanExecute method on that command. It depends // on the implementation of the interface whether this method is available. // RelayCommand and RelayCommand<T> both have it. .Select(pi => pi.GetValue(target, null)); foreach (var commandInterface in commands) { var cmdObj = commandInterface as DelegateCommandBase; if (cmdObj != null) { cmdObj.RaiseCanExecuteChanged(); } } } }
private static bool?ShowDialogInner(BindableBase vm, double width, double heigth, Predicate <object> canSave) { var dlg = new DialogWindow { DataContext = vm, MinHeight = heigth, MinWidth = width, Width = width, Height = heigth, }; var cmd = new CommandBinding( ApplicationCommands.Save, (sender, args) => { }, (sender, args) => args.CanExecute = canSave == null || canSave(args.Parameter)); dlg.CommandBindings.Add(cmd); return(dlg.ShowDialog()); }
private void OnBonusRoundComplete(GameState gs) { gs.NumberOfCompleteBonusRounds += 1; _saveHandler.SaveGame(gs); SetCurrentGameState(gs); CurrentViewModel = _scoringOverviewViewModel; }
/// <summary> /// Attribuzione del ViewModel da mostrare /// </summary> /// <param name="obj"></param> private void OnQdcList(object obj) { if (CurrentViewModel == MenuVM) { CurrentViewModel = QdcVM; } }
private void OnSelezionaList(object obj) { if (CurrentViewModel == MenuVM) { CurrentViewModel = SelezionaVM; } }
public void OnNav(string destination) { switch (destination) { case "home": CurrentViewModel = _startViewModel; break; case "data": CurrentViewModel = _dataViewModel; break; case "newUser": CurrentViewModel = _newUserViewModel; break; case "editProfile": CurrentViewModel = _profileViewModel; break; case "addItem": CurrentViewModel = _addItemViewModel; break; case "oldItem": CurrentViewModel = _addOldItemViewModel; break; case "viewItem": CurrentViewModel = _itemDetailsViewModel; break; } }
private void SetProperties() { CreateViewModels(); Navigacija = new MyICommand <string>(Navig); TrenutniViewModel = homeViewModel; }
public static void TestObservableCollection() { var owner = new BindableBase(); var oc = new ObservableCollection <string>(); var obsc = MvvmRx.ObserveCollectionChanges(owner, oc); var values = MvvmRx.ObserveCollectionValues(owner, oc); obsc.Subscribe(val => { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(val.args.AsString()); }); values.Subscribe(val => { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"[{string.Join<string>(", ", val)}]"); }); oc.Add("A"); oc.Add("B"); oc.Add("C"); oc.Add("D"); oc.Move(1, 3); oc[2] = "E"; oc.RemoveAt(2); oc.Clear(); }
public void Navig(string odabir) { switch (odabir) { case "Home": TrenutniViewModel = homeViewModel; break; case "Trening": TrenutniViewModel = treningViewModel; break; case "Create user": TrenutniViewModel = cRUDUser; break; case "Get admins": TrenutniViewModel = GetAllAdminsViewModel; break; case "Treneri": TrenutniViewModel = TrenerViewModel; break; case "My actions": TrenutniViewModel = MyActionViewModel; break; case "Login": TrenutniViewModel = loginViewModel; break; } }
public MainViewModel() { RegisterCommands(); clvm = new CoffeeListViewModel(); avm = new AboutViewModel(); CurrentViewModel = clvm; }
string IDataErrorInfo.this[string columnName] { get { string KodGrupyProp = BindableBase.GetPropertyName(() => KodGrupy); string NazwaGrupyProp = BindableBase.GetPropertyName(() => NazwaGrupy); string KodZlozonyProp = BindableBase.GetPropertyName(() => KodZlozony); string NazwaZlozonaProp = BindableBase.GetPropertyName(() => NazwaZlozona); if (columnName == KodGrupyProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(KodGrupyProp, KodGrupy)); } if (columnName == NazwaGrupyProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(NazwaGrupyProp, NazwaGrupy)); } if (columnName == KodZlozonyProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(KodZlozonyProp, KodZlozony)); } if (columnName == NazwaZlozonaProp) { return(RequiredValidationRuleGrKart.GetErrorMessage(NazwaZlozonaProp, NazwaZlozona)); } else { return(null); } } }
public MainViewModel() { RegisterCommands(); SyncState = "login required"; CurrentViewModel = ViewModelLocator.Login; }
public ContentSidebarItemView(BindableBase model) { Contract.Requires(model != null); InitializeComponent(); DataContext = model; }
public MainContentViewModel() { _rootDetailsViewModel = new RootDetailsViewModel(); _processDetailsViewModel = new ProcessDetailsViewModel(); _currentDetailsViewModel = _rootDetailsViewModel; // I shouldn't need this, but I just can't get the property change to get the view binding to update _dataModel.PropertyChanged += WtfPropertyChangedEventHandler; }
public void Show(BindableBase ViewModel) { TxJsonWindow myWin = new TxJsonWindow(); myWin.DataContext = ViewModel; myWin.Owner = Application.Current.MainWindow; myWin.ShowDialog(); }
private void AddTab(BindableBase tab, bool select = true) { _tabItems.Add(tab); if (select) { SelectedTab = tab; } }
public static IMenuViewModel CreateMenuSeparator(this BindableBase _) { #pragma warning disable CS0612 // 类型或成员已过时 IMenuViewModel vm = APIHelper.GetIContainer().Resolve <IMenuViewModel>(); #pragma warning restore CS0612 // 类型或成员已过时 vm.IsSeparator = true; return(vm); }
public MainWindowViewModel() { _studentListViewModel.ViewEnrolmentsRequested += NavToEnrolments; _studentListViewModel.EditStudentRequested += NavToEdit; _currentViewModel = _studentListViewModel; NavCommand = new DelegateCommand<string>(OnNav); }
/// <summary> /// 触发事件 /// </summary> /// <typeparam name="TEventArgs">事件类型</typeparam> /// <param name="source">事件来源</param> /// <param name="eventArgs">事件数据</param> /// <param name="callerMemberName">事件名</param> public static void RaiseEvent <TEventArgs>(this BindableBase source, TEventArgs eventArgs, string callerMemberName = "") #if !NETFX_CORE // where TEventArgs : EventArgs #endif { EventRouter.Instance.RaiseEvent(source, eventArgs, callerMemberName); }
public MainWindowViewModel(LandlordListViewModel landlordListViewModel, AddEditPropertyViewModel addEditPropertyViewModel) { this.landlordListViewModel = landlordListViewModel; this.addEditPropertyViewModel = addEditPropertyViewModel; landlordListViewModel.AddPropertyRequested += NavToAddProperty; landlordListViewModel.EditPropertyRequested += NavToEditProperty; addEditPropertyViewModel.Done += AddEditPropertyViewModel_Done; CurrentViewModel = landlordListViewModel; }
/// <summary> /// Determines whether [is in design mode] [the specified view model]. /// </summary> /// <param name="viewModel">The view model.</param> /// <remarks> /// From [http://stackoverflow.com/questions/3757646/how-do-i-stop-my-viewmodel-code-from-running-in-the-designer] /// </remarks> public static bool IsInDesignMode(this BindableBase viewModel) { var test = false; #if DEBUG test = (DesignerProperties.GetIsInDesignMode(new DependencyObject())); #endif return(test); }
private void NavigateTo(string destinationView, bool cancel) { switch (destinationView) { case ViewNames.SpritePropertiesView: LocalRegion = cancel ? null : _spritePropertiesViewModel; break; } }
public static async void ShowRunProgress(BindableBase thisContent, IDialogCoordinator dialogCoordinator, string header, string message, int value) { var controller = await dialogCoordinator.ShowProgressAsync(thisContent, header, message); controller.SetIndeterminate(); await TaskEx.Delay(value); await controller.CloseAsync(); }
public static FilterTreeViewModel <PHASE, PHASE, Guid> GetPHASEFilterTree(object parentViewModel) { return(FilterTreeViewModel <PHASE, PHASE, Guid> .Create( new FilterTreeModelPageSpecificSettings <Settings, PHASE>(Settings.Default, bluePrintsEntitiesUnitOfWork.PHASES, "PHASE", x => x.AllStaticFilters, x => x.PHASECustomFilter, new[] { BindableBase.GetPropertyName(() => new PHASE().GUID) }), bluePrintsEntitiesUnitOfWork.PHASES, new Action <object, Action>(RegisterEntityChangedMessageHandler <PHASE, Guid>) ).SetParentViewModel(parentViewModel)); }
public static FilterTreeViewModel <Customer, long> GetCustomersFilterTree(object parentViewModel) { return(FilterTreeViewModel <Customer, long> .Create( new FilterTreeModelPageSpecificSettings <Settings>(Settings.Default, "Favorites", x => x.CustomersStaticFilters, x => x.CustomersCustomFilters, null, new[] { BindableBase.GetPropertyName(() => new Customer().Id), }), CreateUnitOfWork().Customers, (recipient, handler) => RegisterEntityChangedMessageHandler <Customer, long>(recipient, handler) ).SetParentViewModel(parentViewModel)); }
public static FilterTreeViewModel <Employee, long> GetEmployeesFilterTree(object parentViewModel) { return(FilterTreeViewModel <Employee, long> .Create( new FilterTreeModelPageSpecificSettings <Settings>(Settings.Default, "Status", x => x.EmployeesStaticFilters, x => x.EmployeesCustomFilters, null, new[] { BindableBase.GetPropertyName(() => new Employee().FullName), BindableBase.GetPropertyName(() => new Employee().Id), }), CreateUnitOfWork().Employees, (recipient, handler) => RegisterEntityChangedMessageHandler <Employee, long>(recipient, handler) ).SetParentViewModel(parentViewModel)); }
public RequestCommand(BindableBase vm, IRequestListener listener) { this.vm = vm; this.listener = listener; }