This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
TaskCollectionView.cs
52 lines (49 loc) · 1.92 KB
/
TaskCollectionView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyMvpvmApplication.ViewModels;
using DevExpress.Mvvm.POCO;
using MyMvpvmApplication.Model;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
namespace MyMvpvmApplication.Views {
public partial class TaskCollectionView : UserControl {
public TaskCollectionView() {
InitializeComponent();
viewModelCore = ViewModelSource.Create<TaskCollectionViewModel>();
presenterCore = new TaskCollectionPresenter(gridControl1, ViewModel);
BindCommands();
}
TaskCollectionViewModel viewModelCore;
public TaskCollectionViewModel ViewModel {
get { return viewModelCore; }
}
TaskCollectionPresenter presenterCore;
public TaskCollectionPresenter Presenter {
get { return presenterCore; }
}
void BindCommands() {
biAddTask.BindCommand(() => ViewModel.AddTask(), ViewModel);
biDeleteTask.BindCommand(() => ViewModel.DeleteTask(null), ViewModel, () => ViewModel.SelectedTask);
}
}
public class TaskCollectionPresenter {
public TaskCollectionPresenter(GridControl grid, TaskCollectionViewModel viewModel) {
viewModelCore = viewModel;
((ColumnView)grid.MainView).FocusedRowObjectChanged += gridView1_FocusedRowObjectChanged;
(grid.DataSource as BindingSource).DataSource = ViewModel.Tasks;
}
void gridView1_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e) {
ViewModel.SelectedTask = e.Row as Task;
}
TaskCollectionViewModel viewModelCore;
public TaskCollectionViewModel ViewModel {
get { return viewModelCore; }
}
}
}