markus / KCOM / Messenger / MessageBase.cs @ 99b9f32a
이력 | 보기 | 이력해설 | 다운로드 (4.16 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Collections.ObjectModel; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Windows; |
7 |
using System.Windows.Controls; |
8 |
|
9 |
namespace KCOM.Messenger |
10 |
{ |
11 |
public enum MessageSide |
12 |
{ |
13 |
Me, |
14 |
You |
15 |
} |
16 |
|
17 |
public enum MessageType |
18 |
{ |
19 |
Normal, |
20 |
Anchor |
21 |
} |
22 |
|
23 |
/// <summary> |
24 |
/// An SMS message |
25 |
/// </summary> |
26 |
public class Message |
27 |
{ |
28 |
private static DateTime _now = DateTime.Now; |
29 |
private static Random _rand = new Random(); |
30 |
|
31 |
public Message() |
32 |
{ |
33 |
Timestamp = _now; |
34 |
_now = _now.AddMinutes(_rand.Next(100)); |
35 |
ClickAnchorCommand = new Telerik.Windows.Controls.DelegateCommand(SaveAuthorization); |
36 |
} |
37 |
private void SaveAuthorization(object parameter) |
38 |
{ |
39 |
Message instance = parameter as Message; |
40 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(instance.PageNumber); |
41 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(instance.AnchorBound); |
42 |
} |
43 |
|
44 |
public string Text { get; set; } |
45 |
public DateTime Timestamp { get; set; } |
46 |
public MessageSide Side { get; set; } |
47 |
public MessageType MsgStype { get; set; } |
48 |
public string UserName { get; set; } |
49 |
public Rect AnchorBound { get; set; } |
50 |
public int PageNumber { get; set; } |
51 |
|
52 |
|
53 |
public Telerik.Windows.Controls.DelegateCommand ClickAnchorCommand { get; set; } |
54 |
|
55 |
|
56 |
} |
57 |
|
58 |
/// <summary> |
59 |
/// A collection of messages |
60 |
/// </summary> |
61 |
public class MessageCollection : ObservableCollection<KCOMDataModel.DataModel.TALK> |
62 |
{ |
63 |
public MessageCollection() |
64 |
{ |
65 |
//ClickAnchorCommand = new Telerik.Windows.Controls.DelegateCommand(SaveAuthorization); |
66 |
} |
67 |
//private void SaveAuthorization(object parameter) |
68 |
//{ |
69 |
// Message instance = parameter as Message; |
70 |
// Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(instance.PageNumber); |
71 |
// Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(instance.AnchorBound); |
72 |
//} |
73 |
//public Telerik.Windows.Controls.DelegateCommand ClickAnchorCommand { get; set; } |
74 |
} |
75 |
|
76 |
public class MessageContentPresenter : ContentControl |
77 |
{ |
78 |
/// <summary> |
79 |
/// The DataTemplate to use when Message.Side == Side.Me |
80 |
/// </summary> |
81 |
public DataTemplate MeTemplate { get; set; } |
82 |
|
83 |
/// <summary> |
84 |
/// The DataTemplate to use when Message.Side == Side.You |
85 |
/// </summary> |
86 |
public DataTemplate YouTemplate { get; set; } |
87 |
|
88 |
protected override void OnContentChanged(object oldContent, object newContent) |
89 |
{ |
90 |
base.OnContentChanged(oldContent, newContent); |
91 |
|
92 |
// apply the required template |
93 |
KCOMDataModel.DataModel.TALK message = newContent as KCOMDataModel.DataModel.TALK; |
94 |
if (message == null) |
95 |
{ |
96 |
message = oldContent as KCOMDataModel.DataModel.TALK; |
97 |
} |
98 |
else |
99 |
{ |
100 |
if ((MessageType)message.MSGTYPE == MessageType.Normal) |
101 |
{ |
102 |
if ((MessageSide)message.MSGSIDE == MessageSide.Me) |
103 |
{ |
104 |
ContentTemplate = App.Current.Resources["MeTemplate"] as DataTemplate; |
105 |
//ContentTemplate = MeTemplate; |
106 |
} |
107 |
else |
108 |
{ |
109 |
ContentTemplate = App.Current.Resources["YouTemplate"] as DataTemplate; |
110 |
} |
111 |
} |
112 |
else |
113 |
{ |
114 |
if ((MessageSide)message.MSGSIDE == MessageSide.Me) |
115 |
{ |
116 |
ContentTemplate = App.Current.Resources["MeTemplate_Anchor"] as DataTemplate; |
117 |
//ContentTemplate = MeTemplate; |
118 |
} |
119 |
else |
120 |
{ |
121 |
ContentTemplate = App.Current.Resources["YouTemplate_Anchor"] as DataTemplate; |
122 |
} |
123 |
|
124 |
|
125 |
} |
126 |
} |
127 |
} |
128 |
} |
129 |
} |