public void SetModel(Model model) { this.model = model; Students = new ObservableCollection <Student>(model.GetStudents()); CreateStudent = new MvvmCommand( () => { PageManager.ChangePageTo(PageType.EditStudent); model.EditStudent(model.CreateStudent()); }, () => true); EditStudent = new MvvmCommand( () => { PageManager.ChangePageTo(PageType.EditStudent); model.EditStudent(SelectedStudent); }, () => SelectedStudent != null); RemoveStudent = new MvvmCommand( () => model.RemoveStudent(SelectedStudent), () => SelectedStudent != null); Duty = new MvvmCommand( () => { PageManager.ChangePageTo(PageType.DutyList); model.Duty(); }, () => Students.Count >= 2); model.StudentsChanged += Model_StudentsChanged; model.BirthdayStudentChanged += Model_BirthdayStudentChanged; model.GetBirthdayStudent(); }
public MvvmCommand(Action <object> execute, Func <object, bool> canExecute = null) { if (execute == null) { throw new ArgumentNullException("command"); } _canExecute = canExecute == null ? parmeter => MvvmCommand.AlwaysCanExecute() : canExecute; _execute = execute; }
public MainVM() { model = new Model(); PageContainer.SetModel(model); CurrentPage = PageContainer.GetPageByType(PageType.StudentList); PageContainer.CurrentPageChanged += PageContainer_CurrentPageChanged; OpenGroupList = new MvvmCommand(() => PageContainer.ChangePageTo(PageType.GroupList), () => true); OpenStudentList = new MvvmCommand(() => PageContainer.ChangePageTo(PageType.StudentList), () => true); }
public MainVM() { model = new Model(); Groups = model.GetGroups(); EditSelectedStudent = new MvvmCommand(() => model.EditStudent(SelectedGroup, SelectedStudent), () => SelectedStudent != null); RemoveSelectedStudent = new MvvmCommand(() => model.RemoveStudent(SelectedGroup, SelectedStudent), () => SelectedStudent != null); CreateStudent = new MvvmCommand(() => model.CreateStudent(SelectedGroup), () => true); model.StudentsChanged += Model_StudentsChanged; }
/// <summary> /// Initializes a new instance of the <see cref="MvvmCommand"/> class. /// </summary> /// <param name="execute">A reference to the execute method.</param> /// <param name="canExecute">A reference to the function that will evaluate if this command can be executed or not.</param> /// <remarks> /// If canExecute is set to null then a static function will be used that always returns true. /// </remarks> public MvvmCommand(Action <object> execute, Func <object, bool> canExecute = null) { // Quick parameter check, we need the command at least. if (execute == null) { throw new ArgumentNullException("command"); } // Hook up the instances. _canExecute = canExecute == null ? parmeter => MvvmCommand.AlwaysCanExecute() : canExecute; _execute = execute; }
public static void FocusCommand(object parameter) { MvvmCommand targetCommand = parameter as MvvmCommand; if (targetCommand != null) { UIElement targetElement = targetCommand.Tag as UIElement; if (targetElement != null) { targetElement.Focus(); } } }
public void SetModel(Model model) { this.model = model; BackToList = new MvvmCommand( () => PageManager.ChangePageTo(PageType.StudentList), () => true); Agree = new MvvmCommand( () => model.SetDuty(FirstStudent, SecondStudent), () => true); model.OnDutyChanged += Model_OnDutyChanged; }
public void SetModel(Model model) { this.model = model; BackToList = new MvvmCommand( () => { PageManager.ChangePageTo(PageType.StudentList); model.NoSaveStudent(); }, () => true); SaveStudent = new MvvmCommand( () => { PageManager.ChangePageTo(PageType.StudentList); model.SaveStudent(); }, () => model.CanSave(SelectedStudent)); model.SelectedStudentChanged += Model_SelectedStudentChanged; }
public MainVM() { game = new Game(); TryWord = game.GetStartWord().Select(s => new ViewChar(s)); CommandTry = new MvvmCommand( () => game.TryWord(), () => game.Status); CommandStart = new MvvmCommand( () => game.StartGame(), () => !game.Status); game.ImageChanged += Game_ImageChanged; game.WordStatusChanged += Game_WordStatusChanged; }
public void SetModel(Model model) { this.model = model; UpdateGroups(); CreateGroup = new MvvmCommand( () => model.CreateGroup(CreateGroupName), () => !string.IsNullOrEmpty(CreateGroupName)); RemoveGroup = new MvvmCommand( () => model.RemoveGroup(SelectedGroup), () => true); model.GroupsChanged += Model_GroupsChanged; }
/// <summary> /// Initializes this instance. /// </summary> private void Initialize() { SearchCommand = new MvvmCommand( (parm) => { IQueryable <Employee> result = from e in repository.GetList <Employee>() where e.FirstName.Contains(SearchText) || e.LastName.Contains(SearchText) select e; Model.Clear(); result.ToList().ForEach(e => Model.Add(e)); }, (parm) => { return(true); }); SelectedEmployeeChanged = new MvvmCommand( (parm) => { if (parm is Employee) { SelectedEmployee = (Employee)parm; } }, (parm) => { return(true); }) ; }
/// <summary> /// Initializes this instance. /// </summary> private void Initialize() { SearchCommand = new MvvmCommand( (parm) => { IQueryable <Customer> result = from c in repository.GetList <Customer>() where c.FirstName.Contains(SearchText) || c.LastName.Contains(SearchText) select c; Model.Clear(); result.ToList().ForEach(c => Model.Add(c)); }, (parm) => true); SelectedCustomerChanged = new MvvmCommand( (parm) => { if (parm is Customer) { SelectedCustomer = (Customer)parm; } }, (parm) => { return(true); }) ; }
/// <summary> /// Initializes this instance. /// </summary> private void Initialize() { SearchCommand = new MvvmCommand( (parm) => { IQueryable <Product> result = from p in repository.GetList <Product>() where p.Name.Contains(SearchText) || p.Code.Contains(SearchText) select p; Model.Clear(); result.ToList().ForEach(e => model.Add(e)); }, (parm) => { return(true); }); SelectedProductChanged = new MvvmCommand( (parm) => { if (parm is Product) { SelectedProduct = (Product)parm; } }, (parm) => { return(true); }) ; }
public void SetModel(Model model) { this.model = model; Back = new MvvmCommand(() => Pages.ChangePageTo(PageType.ClientList), () => true); model.SelectedClientChanged += Model_SelectedClientChanged; }
public GetContactVM(GetContact getContact) { Contact = Model.GetInstance().EditContact; SaveContact = new Mvvm1125.MvvmCommand(() => { getContact.Close(); Model.GetInstance().Save(); }, () => true); }
public void SetModel(Model model) { this.model = model; Return = new MvvmCommand(() => Pages.ChangePageTo(PageType.StudentList), () => true); Random = new MvvmCommand( () => }