-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommentView.xaml.cs
570 lines (493 loc) · 19.2 KB
/
CommentView.xaml.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Trivial.Text;
using Windows.UI.Text;
using Trivial.Data;
namespace Trivial.UI;
using DependencyObjectProxy = DependencyObjectProxy<CommentView>;
/// <summary>
/// The comment item view.
/// </summary>
public sealed partial class CommentView : UserControl
{
/// <summary>
/// The dependency property of reply stack panel style.
/// </summary>
public static readonly DependencyProperty ReplyPanelStyleProperty = DependencyObjectProxy.RegisterProperty<Style>(nameof(ReplyPanelStyle), (c, e, d) => c.ReplyPanelStyle = e.NewValue);
/// <summary>
/// The dependency property of avatar URI.
/// </summary>
public static readonly DependencyProperty AvatarUriProperty = DependencyObjectProxy.RegisterProperty<Uri>(nameof(AvatarUri));
/// <summary>
/// The dependency property of nickname.
/// </summary>
public static readonly DependencyProperty NicknameProperty = DependencyObjectProxy.RegisterProperty<string>(nameof(Nickname), OnTextChanged);
/// <summary>
/// The dependency property of publish description.
/// </summary>
public static readonly DependencyProperty DescriptionProperty = DependencyObjectProxy.RegisterProperty<string>(nameof(Description), OnTextChanged);
/// <summary>
/// The dependency property of content text.
/// </summary>
public static readonly DependencyProperty TextProperty = DependencyObjectProxy.RegisterProperty<string>(nameof(Text), OnTextChanged);
/// <summary>
/// The dependency property of content margin.
/// </summary>
public static readonly DependencyProperty ContentMarginProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(ContentMargin));
/// <summary>
/// The dependency property of content height.
/// </summary>
public static readonly DependencyProperty ContentHeightProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(ContentHeight));
/// <summary>
/// The dependency property of sender information margin.
/// </summary>
public static readonly DependencyProperty SenderMarginProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(SenderMargin));
/// <summary>
/// The dependency property of sender information orientation.
/// </summary>
public static readonly DependencyProperty SenderOrientationProperty = DependencyObjectProxy.RegisterProperty(nameof(SenderOrientation), Orientation.Vertical);
/// <summary>
/// The dependency property of sender information trimming.
/// </summary>
public static readonly DependencyProperty SenderTrimmingProperty = DependencyObjectProxy.RegisterProperty<TextTrimming>(nameof(SenderTrimming));
/// <summary>
/// The dependency property of sender spacing.
/// </summary>
public static readonly DependencyProperty SenderSpacingProperty = DependencyObjectProxy.RegisterProperty(nameof(SenderSpacing), 0d);
/// <summary>
/// The dependency property of text horiontal text alignment.
/// </summary>
public static readonly DependencyProperty HorizontalTextAlignmentProperty = DependencyObjectProxy.RegisterProperty(nameof(HorizontalTextAlignment), TextAlignment.Left);
/// <summary>
/// The dependency property of nickname font size.
/// </summary>
public static readonly DependencyProperty NicknameFontSizeProperty = DependencyObjectProxy.RegisterProperty(nameof(NicknameFontSize), 12d);
/// <summary>
/// The dependency property of nickname font weight.
/// </summary>
public static readonly DependencyProperty NicknameFontWeightProperty = DependencyObjectProxy.RegisterFontWeightProperty(nameof(NicknameFontWeight));
/// <summary>
/// The dependency property of nickname font style.
/// </summary>
public static readonly DependencyProperty NicknameFontStyleProperty = DependencyObjectProxy.RegisterProperty<FontStyle>(nameof(NicknameFontStyle));
/// <summary>
/// The dependency property of nickname line height.
/// </summary>
public static readonly DependencyProperty NicknameLineHeightProperty = DependencyObjectProxy.RegisterProperty(nameof(NicknameLineHeight), 0d);
/// <summary>
/// The dependency property of nickname foreground.
/// </summary>
public static readonly DependencyProperty NicknameForegroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(NicknameForeground));
/// <summary>
/// The dependency property of nickname width.
/// </summary>
public static readonly DependencyProperty NicknameWidthProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(NicknameWidth));
/// <summary>
/// The dependency property of nickname height.
/// </summary>
public static readonly DependencyProperty NicknameHeightProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(NicknameHeight));
/// <summary>
/// The dependency property of description font size.
/// </summary>
public static readonly DependencyProperty DescriptionFontSizeProperty = DependencyObjectProxy.RegisterProperty(nameof(DescriptionFontSize), 11d);
/// <summary>
/// The dependency property of description font weight.
/// </summary>
public static readonly DependencyProperty DescriptionFontWeightProperty = DependencyObjectProxy.RegisterFontWeightProperty(nameof(DescriptionFontWeight));
/// <summary>
/// The dependency property of description font style.
/// </summary>
public static readonly DependencyProperty DescriptionFontStyleProperty = DependencyObjectProxy.RegisterProperty<FontStyle>(nameof(DescriptionFontStyle));
/// <summary>
/// The dependency property of description line height.
/// </summary>
public static readonly DependencyProperty DescriptionLineHeightProperty = DependencyObjectProxy.RegisterProperty(nameof(DescriptionLineHeight), 0d);
/// <summary>
/// The dependency property of description foreground.
/// </summary>
public static readonly DependencyProperty DescriptionForegroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(DescriptionForeground));
/// <summary>
/// The dependency property of description width.
/// </summary>
public static readonly DependencyProperty DescriptionWidthProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(DescriptionWidth));
/// <summary>
/// The dependency property of description height.
/// </summary>
public static readonly DependencyProperty DescriptionHeightProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(DescriptionHeight));
/// <summary>
/// The dependency property of avatar image width.
/// </summary>
public static readonly DependencyProperty AvatarWidthProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(AvatarWidth));
/// <summary>
/// The dependency property of avatar image height.
/// </summary>
public static readonly DependencyProperty AvatarHeightProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(AvatarHeight));
/// <summary>
/// The dependency property of avatar image background.
/// </summary>
public static readonly DependencyProperty AvatarBackgroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(AvatarBackground));
/// <summary>
/// The dependency property of avatar image background sizing.
/// </summary>
public static readonly DependencyProperty AvatarBackgroundSizingProperty = DependencyObjectProxy.RegisterProperty<BackgroundSizing>(nameof(AvatarBackgroundSizing));
/// <summary>
/// The dependency property of avatar image margin.
/// </summary>
public static readonly DependencyProperty AvatarMarginProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(AvatarMargin));
/// <summary>
/// The dependency property of avatar image corner radius.
/// </summary>
public static readonly DependencyProperty AvatarCornerRadiusProperty = DependencyObjectProxy.RegisterProperty<CornerRadius>(nameof(AvatarCornerRadius));
/// <summary>
/// The dependency property of reply visibility.
/// </summary>
public static readonly DependencyProperty ReplyVisibilityProperty = DependencyObjectProxy.RegisterProperty<Visibility>(nameof(ReplyVisibility), Visibility.Collapsed);
/// <summary>
/// Initializes a new instance of the CommentView class.
/// </summary>
public CommentView()
{
InitializeComponent();
}
/// <summary>
/// Gets or sets the avatar URI of sender.
/// </summary>
public Uri AvatarUri
{
get => (Uri)GetValue(AvatarUriProperty);
set => SetValue(AvatarUriProperty, value);
}
/// <summary>
/// Gets or sets the nickname of sender.
/// </summary>
public string Nickname
{
get => (string)GetValue(NicknameProperty);
set => SetValue(NicknameProperty, value);
}
/// <summary>
/// Gets or sets the publish description.
/// </summary>
public string Description
{
get => (string)GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}
/// <summary>
/// Gets or sets the content text.
/// </summary>
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
/// <summary>
/// Gets or sets the height of content.
/// </summary>
public double ContentHeight
{
get => (double)GetValue(ContentHeightProperty);
set => SetValue(ContentHeightProperty, value);
}
/// <summary>
/// Gets or sets the margin of content.
/// </summary>
public Thickness ContentMargin
{
get => (Thickness)GetValue(ContentMarginProperty);
set => SetValue(ContentMarginProperty, value);
}
/// <summary>
/// Gets or sets the margin of sender information.
/// </summary>
public Thickness SenderMargin
{
get => (Thickness)GetValue(SenderMarginProperty);
set => SetValue(SenderMarginProperty, value);
}
/// <summary>
/// Gets or sets the spacing between each sender information.
/// </summary>
public double SenderSpacing
{
get => (double)GetValue(SenderSpacingProperty);
set => SetValue(SenderSpacingProperty, value);
}
/// <summary>
/// Gets or sets the alignment of text zone.
/// </summary>
public TextAlignment HorizontalTextAlignment
{
get => (TextAlignment)GetValue(HorizontalTextAlignmentProperty);
set => SetValue(HorizontalTextAlignmentProperty, value);
}
/// <summary>
/// Gets or sets the orientation of the image and text.
/// </summary>
public Orientation SenderOrientation
{
get => (Orientation)GetValue(SenderOrientationProperty);
set => SetValue(SenderOrientationProperty, value);
}
/// <summary>
/// Gets or sets the trimming mode of title.
/// </summary>
public TextTrimming SenderTrimming
{
get => (TextTrimming)GetValue(SenderTrimmingProperty);
set => SetValue(SenderTrimmingProperty, value);
}
/// <summary>
/// Gets or sets the font size of nickname.
/// </summary>
public double NicknameFontSize
{
get => (double)GetValue(NicknameFontSizeProperty);
set => SetValue(NicknameFontSizeProperty, value);
}
/// <summary>
/// Gets or sets the font weight of nickname.
/// </summary>
public FontWeight NicknameFontWeight
{
get => (FontWeight)GetValue(NicknameFontWeightProperty);
set => SetValue(NicknameFontWeightProperty, value);
}
/// <summary>
/// Gets or sets the font style of nickname.
/// </summary>
public FontStyle NicknameFontStyle
{
get => (FontStyle)GetValue(NicknameFontStyleProperty);
set => SetValue(NicknameFontStyleProperty, value);
}
/// <summary>
/// Gets or sets the line height of nickname.
/// </summary>
public double NicknameLineHeight
{
get => (double)GetValue(NicknameLineHeightProperty);
set => SetValue(NicknameLineHeightProperty, value);
}
/// <summary>
/// Gets or sets the foreground of nickname.
/// </summary>
public Brush NicknameForeground
{
get => (Brush)GetValue(NicknameForegroundProperty);
set => SetValue(NicknameForegroundProperty, value);
}
/// <summary>
/// Gets or sets the width of nickname.
/// </summary>
public double NicknameWidth
{
get => (double)GetValue(NicknameWidthProperty);
set => SetValue(NicknameWidthProperty, value);
}
/// <summary>
/// Gets or sets the height of nickname.
/// </summary>
public double NicknameHeight
{
get => (double)GetValue(NicknameHeightProperty);
set => SetValue(NicknameHeightProperty, value);
}
/// <summary>
/// Gets or sets the font size of description.
/// </summary>
public double DescriptionFontSize
{
get => (double)GetValue(DescriptionFontSizeProperty);
set => SetValue(DescriptionFontSizeProperty, value);
}
/// <summary>
/// Gets or sets the font weight of description.
/// </summary>
public FontWeight DescriptionFontWeight
{
get => (FontWeight)GetValue(DescriptionFontWeightProperty);
set => SetValue(DescriptionFontWeightProperty, value);
}
/// <summary>
/// Gets or sets the font style of description.
/// </summary>
public FontStyle DescriptionFontStyle
{
get => (FontStyle)GetValue(DescriptionFontStyleProperty);
set => SetValue(DescriptionFontStyleProperty, value);
}
/// <summary>
/// Gets or sets the line height of description.
/// </summary>
public double DescriptionLineHeight
{
get => (double)GetValue(DescriptionLineHeightProperty);
set => SetValue(DescriptionLineHeightProperty, value);
}
/// <summary>
/// Gets or sets the foreground of description.
/// </summary>
public Brush DescriptionForeground
{
get => (Brush)GetValue(DescriptionForegroundProperty);
set => SetValue(DescriptionForegroundProperty, value);
}
/// <summary>
/// Gets or sets the width of description.
/// </summary>
public double DescriptionWidth
{
get => (double)GetValue(DescriptionWidthProperty);
set => SetValue(DescriptionWidthProperty, value);
}
/// <summary>
/// Gets or sets the height of description.
/// </summary>
public double DescriptionHeight
{
get => (double)GetValue(DescriptionHeightProperty);
set => SetValue(DescriptionHeightProperty, value);
}
/// <summary>
/// Gets or sets the width of avatar image.
/// </summary>
public double AvatarWidth
{
get => (double)GetValue(AvatarWidthProperty);
set => SetValue(AvatarWidthProperty, value);
}
/// <summary>
/// Gets or sets the height of avatar image.
/// </summary>
public double AvatarHeight
{
get => (double)GetValue(AvatarHeightProperty);
set => SetValue(AvatarHeightProperty, value);
}
/// <summary>
/// Gets or sets the background of avatar image.
/// </summary>
public Brush AvatarBackground
{
get => (Brush)GetValue(AvatarBackgroundProperty);
set => SetValue(AvatarBackgroundProperty, value);
}
/// <summary>
/// Gets or sets the corner radius of avatar image.
/// </summary>
public CornerRadius AvatarCornerRadius
{
get => (CornerRadius)GetValue(AvatarCornerRadiusProperty);
set => SetValue(AvatarCornerRadiusProperty, value);
}
/// <summary>
/// Gets or sets the background sizing of avatar image.
/// </summary>
public BackgroundSizing AvatarBackgroundSizing
{
get => (BackgroundSizing)GetValue(AvatarBackgroundSizingProperty);
set => SetValue(AvatarBackgroundSizingProperty, value);
}
/// <summary>
/// Gets or sets the margin of avatar image.
/// </summary>
public Thickness AvatarMargin
{
get => (Thickness)GetValue(AvatarMarginProperty);
set => SetValue(AvatarMarginProperty, value);
}
/// <summary>
/// Gets or sets the visibility of reply panel.
/// </summary>
public Visibility ReplyVisibility
{
get => (Visibility)GetValue(ReplyVisibilityProperty);
set => SetValue(ReplyVisibilityProperty, value);
}
/// <summary>
/// Gets or sets the style of reply stack panel.
/// </summary>
public Style ReplyPanelStyle
{
get => (Style)GetValue(ReplyPanelStyleProperty);
set => SetValue(ReplyPanelStyleProperty, value);
}
/// <summary>
/// Gets the children of reply stack panel.
/// </summary>
public UIElementCollection ReplyChildren => ReplayPanel.Children;
/// <summary>
/// Gets or sets the content of child.
/// </summary>
public UIElement Child
{
get => ContentPanel.Child;
set => ContentPanel.Child = value;
}
/// <summary>
/// Gets or sets the content of additional sender information.
/// </summary>
public UIElement SenderAdditionalContent
{
get => SenderAdditionalInfo.Child;
set => SenderAdditionalInfo.Child = value;
}
/// <summary>
/// Gets or sets the content of background.
/// </summary>
public UIElement BackgroundContent
{
get => BackgroundPanel.Child;
set => BackgroundPanel.Child = value;
}
/// <summary>
/// Gets or sets the content of sender corner.
/// </summary>
public UIElement SenderCornerContent
{
get => SenderCornerPanel.Child;
set => SenderCornerPanel.Child = value;
}
/// <summary>
/// Gets or sets the content of before customized zone.
/// </summary>
public UIElement BeforeContent
{
get => BeforeContentPanel.Child;
set => BeforeContentPanel.Child = value;
}
/// <summary>
/// Gets or sets the content of after customized zone.
/// </summary>
public UIElement AfterContent
{
get => AfterContentPanel.Child;
set => AfterContentPanel.Child = value;
}
/// <summary>
/// Sets publish date as description
/// </summary>
/// <param name="date">The date time to publish.</param>
/// <returns>The result of description.</returns>
public string SetPublishDate(DateTime date)
=> Description = date.Date == DateTime.Now.Date ? date.ToShortTimeString() : date.ToShortDateString();
private static void OnTextChanged(CommentView c, ChangeEventArgs<string> e, DependencyProperty p)
{
c.NicknameText.Visibility = string.IsNullOrWhiteSpace(c.Nickname) ? Visibility.Collapsed : Visibility.Visible;
c.DescriptionText.Visibility = string.IsNullOrWhiteSpace(c.Description) ? Visibility.Collapsed : Visibility.Visible;
c.ContentText.Visibility = string.IsNullOrWhiteSpace(c.Text) ? Visibility.Collapsed : Visibility.Visible;
}
}