This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewModel.cs
80 lines (70 loc) · 2.74 KB
/
ViewModel.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Input;
using DevExpress.Xpf.Core.Commands;
using DevExpress.Xpf.Printing;
namespace E4589 {
class ViewModel : INotifyPropertyChanged {
string[] data;
DelegateCommand<object> createDocumentCommand;
DelegateCommand<object> clearDocumentCommand;
LinkPreviewModel previewModel;
public IDocumentPreviewModel PreviewModel {
get {
if(previewModel == null) {
previewModel = new LinkPreviewModel();
previewModel.Link = CreateLink();
}
return previewModel;
}
}
public ICommand CreateDocumentCommand {
get {
if(createDocumentCommand == null)
createDocumentCommand = new DelegateCommand<object>(ExecuteCreateDocumentCommand, CanExecuteCreateDocumentCommand);
return createDocumentCommand;
}
}
public ICommand ClearDocumentCommand {
get {
if(clearDocumentCommand == null)
clearDocumentCommand = new DelegateCommand<object>(ExecuteClearDocumentCommand, CanExecuteClearDocumentCommand);
return clearDocumentCommand;
}
}
bool CanExecuteCreateDocumentCommand(object parameter) {
return true;
}
void ExecuteCreateDocumentCommand(object parameter) {
((LinkPreviewModel)PreviewModel).Link.CreateDocument(true);
clearDocumentCommand.RaiseCanExecuteChanged();
}
bool CanExecuteClearDocumentCommand(object parameter) {
return !PreviewModel.IsEmptyDocument;
}
void ExecuteClearDocumentCommand(object parameter) {
previewModel.Link.PrintingSystem.ClearContent();
clearDocumentCommand.RaiseCanExecuteChanged();
}
LinkBase CreateLink() {
data = CultureInfo.CurrentCulture.DateTimeFormat.DayNames;
var link = new SimpleLink();
link.DetailTemplate = (DataTemplate)Resources.Instance["dayNameTemplate"];
link.DetailCount = data.Length;
link.CreateDetail += link_CreateDetail;
return link;
}
void link_CreateDetail(object sender, CreateAreaEventArgs e) {
e.Data = data[e.DetailIndex];
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string propertyName) {
if(PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}