1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Controls;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.MainForm.WPF {
|
---|
8 |
|
---|
9 | public abstract class WPFView : UserControl, IView {
|
---|
10 |
|
---|
11 | private string caption = "WPF View";
|
---|
12 | public string Caption {
|
---|
13 | get {
|
---|
14 | return caption;
|
---|
15 | }
|
---|
16 | set {
|
---|
17 | if (value == caption) return;
|
---|
18 | if (value == null) throw new ArgumentNullException("View caption cannot be null");
|
---|
19 | caption = value;
|
---|
20 | OnCaptionChanged();
|
---|
21 | }
|
---|
22 | }
|
---|
23 | public event EventHandler CaptionChanged;
|
---|
24 | protected void OnCaptionChanged() {
|
---|
25 | EventHandler handler = CaptionChanged;
|
---|
26 | if (handler != null)
|
---|
27 | handler(this, EventArgs.Empty);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public event EventHandler Changed;
|
---|
31 |
|
---|
32 | protected void OnChanged() {
|
---|
33 | EventHandler handler = Changed;
|
---|
34 | if (handler != null)
|
---|
35 | handler(this, EventArgs.Empty);
|
---|
36 | }
|
---|
37 |
|
---|
38 | public virtual void Close() {
|
---|
39 | MainFormManager.GetMainForm<WPFMainFormBase>().CloseView(this);
|
---|
40 | IsShown = false;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void Hide() {
|
---|
44 | MainFormManager.GetMainForm<WPFMainFormBase>().HideView(this);
|
---|
45 | IsShown = false;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public bool IsShown { get; protected set; }
|
---|
49 |
|
---|
50 | private bool readOnly = false;
|
---|
51 | public bool ReadOnly {
|
---|
52 | get {
|
---|
53 | return readOnly;
|
---|
54 | }
|
---|
55 | set {
|
---|
56 | if (value == readOnly) return;
|
---|
57 | readOnly = value;
|
---|
58 | OnReadOnlyChanged();
|
---|
59 | }
|
---|
60 | }
|
---|
61 | public event EventHandler ReadOnlyChanged;
|
---|
62 | protected void OnReadOnlyChanged() {
|
---|
63 | EventHandler handler = ReadOnlyChanged;
|
---|
64 | if (handler != null)
|
---|
65 | handler(this, EventArgs.Empty);
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected abstract void OnFirstTimeShown();
|
---|
69 |
|
---|
70 | public void Show() {
|
---|
71 | if (MainFormManager.GetMainForm<WPFMainFormBase>().ShowView(this))
|
---|
72 | OnFirstTimeShown();
|
---|
73 | IsShown = true;
|
---|
74 | }
|
---|
75 |
|
---|
76 | }
|
---|
77 | }
|
---|