예제 #1
0
        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();
        }
예제 #2
0
 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;
 }
예제 #3
0
 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);
 }
예제 #4
0
        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;
        }
예제 #6
0
        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();
                }
            }
        }
예제 #7
0
        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;
        }
예제 #8
0
        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;
        }
예제 #9
0
 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;
 }
예제 #10
0
        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); })
     ;
 }
예제 #14
0
 public void SetModel(Model model)
 {
     this.model = model;
     Back       = new MvvmCommand(() => Pages.ChangePageTo(PageType.ClientList), () => true);
     model.SelectedClientChanged += Model_SelectedClientChanged;
 }
예제 #15
0
 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( () => 
 }