-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextButton.xaml.cs
750 lines (648 loc) · 24.5 KB
/
TextButton.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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Windows.Input;
using Trivial.Data;
using Trivial.Tasks;
using Trivial.Text;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Text;
namespace Trivial.UI;
using DependencyObjectProxy = DependencyObjectProxy<TextButton>;
/// <summary>
/// The common basic button with styled states.
/// </summary>
public sealed partial class TextButton : UserControl
{
/// <summary>
/// The dependency property of click mode.
/// </summary>
public static readonly DependencyProperty ClickModeProperty = DependencyObjectProxy.RegisterProperty<ClickMode>(nameof(ClickMode), (c, e, p) => c.ClickMode = e.NewValue);
/// <summary>
/// The dependency property of command.
/// </summary>
public static readonly DependencyProperty CommandProperty = DependencyObjectProxy.RegisterProperty<ICommand>(nameof(Command), (c, e, p) => c.Command = e.NewValue);
/// <summary>
/// The dependency property of command parameter.
/// </summary>
public static readonly DependencyProperty CommandParameterProperty = DependencyObjectProxy.RegisterProperty<object>(nameof(CommandParameter), (c, e, p) => c.CommandParameter = e.NewValue);
/// <summary>
/// The dependency property of additional state property.
/// </summary>
public static readonly DependencyProperty AdditionalStateProperty = DependencyObjectProxy.RegisterProperty<string>(nameof(AdditionalState));
/// <summary>
/// The dependency property of text property.
/// </summary>
public static readonly DependencyProperty TextProperty = DependencyObjectProxy.RegisterProperty<string>(nameof(Text));
/// <summary>
/// The dependency property of horiontal text alignment.
/// </summary>
public static readonly DependencyProperty HorizontalTextAlignmentProperty = DependencyObjectProxy.RegisterProperty(nameof(HorizontalTextAlignment), TextAlignment.Left);
/// <summary>
/// The dependency property of orientation.
/// </summary>
public static readonly DependencyProperty OrientationProperty = DependencyObjectProxy.RegisterProperty(nameof(Orientation), Orientation.Horizontal);
/// <summary>
/// The dependency property of content horizontal alignment.
/// </summary>
public static readonly DependencyProperty HorizontalItemAlignmentProperty = DependencyObjectProxy.RegisterProperty(nameof(HorizontalItemAlignment), HorizontalAlignment.Center);
/// <summary>
/// The dependency property of content vertical alignment.
/// </summary>
public static readonly DependencyProperty VerticalItemAlignmentProperty = DependencyObjectProxy.RegisterProperty(nameof(VerticalItemAlignment), VerticalAlignment.Center);
/// <summary>
/// The dependency property of spacing.
/// </summary>
public static readonly DependencyProperty SpacingProperty = DependencyObjectProxy.RegisterProperty(nameof(Spacing), OnSpacingChanged, 0d);
/// <summary>
/// The dependency property of hover foreground.
/// </summary>
public static readonly DependencyProperty HoverForegroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(HoverForeground));
/// <summary>
/// The dependency property of disabled foreground.
/// </summary>
public static readonly DependencyProperty DisabledForegroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(DisabledForeground));
/// <summary>
/// The dependency property of base background.
/// </summary>
public static readonly DependencyProperty NormalBackgroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(NormalBackground));
/// <summary>
/// The dependency property of hover background.
/// </summary>
public static readonly DependencyProperty HoverBackgroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(HoverBackground));
/// <summary>
/// The dependency property of disabled background.
/// </summary>
public static readonly DependencyProperty DisabledBackgroundProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(DisabledBackground));
/// <summary>
/// The dependency property of normal border brush.
/// </summary>
public static readonly DependencyProperty NormalBorderBrushProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(NormalBorderBrush));
/// <summary>
/// The dependency property of hover border brush.
/// </summary>
public static readonly DependencyProperty HoverBorderBrushProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(HoverBorderBrush));
/// <summary>
/// The dependency property of disabled border brush.
/// </summary>
public static readonly DependencyProperty DisabledBorderBrushProperty = DependencyObjectProxy.RegisterProperty<Brush>(nameof(DisabledBorderBrush));
/// <summary>
/// The dependency property of normal border thickness.
/// </summary>
public static readonly DependencyProperty NormalBorderThicknessProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(NormalBorderThickness));
/// <summary>
/// The dependency property of hover border thickness.
/// </summary>
public static readonly DependencyProperty HoverBorderThicknessProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(HoverBorderThickness));
/// <summary>
/// The dependency property of disabled border thickness.
/// </summary>
public static readonly DependencyProperty DisabledBorderThicknessProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(DisabledBorderThickness));
/// <summary>
/// The dependency property of panel opacity on disabled.
/// </summary>
public static readonly DependencyProperty DisabledPanelOpacityProperty = DependencyObjectProxy.RegisterProperty(nameof(DisabledPanelOpacity), 0d);
/// <summary>
/// The dependency property of text margin.
/// </summary>
public static readonly DependencyProperty TextMarginProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(TextMargin));
/// <summary>
/// The dependency property of text wrapping.
/// </summary>
public static readonly DependencyProperty TextWrappingProperty = DependencyObjectProxy.RegisterProperty<TextWrapping>(nameof(TextWrapping));
/// <summary>
/// The dependency property of text trimming.
/// </summary>
public static readonly DependencyProperty TextTrimmingProperty = DependencyObjectProxy.RegisterProperty<TextTrimming>(nameof(TextTrimming));
/// <summary>
/// The dependency property of image URI.
/// </summary>
public static readonly DependencyProperty ImageSourceProperty = DependencyObjectProxy.RegisterProperty<ImageSource>(nameof(ImageSource), OnImageUriChanged);
/// <summary>
/// The dependency property of image width.
/// </summary>
public static readonly DependencyProperty ImageWidthProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(ImageWidth));
/// <summary>
/// The dependency property of image height.
/// </summary>
public static readonly DependencyProperty ImageHeightProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(ImageHeight));
/// <summary>
/// The dependency property of image margin.
/// </summary>
public static readonly DependencyProperty ImageMarginProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(ImageMargin));
/// <summary>
/// The dependency property of image corner radius.
/// </summary>
public static readonly DependencyProperty ImageCornerRadiusProperty = DependencyObjectProxy.RegisterProperty<CornerRadius>(nameof(ImageCornerRadius));
/// <summary>
/// The dependency property of image stretch.
/// </summary>
public static readonly DependencyProperty StretchProperty = DependencyObjectProxy.RegisterProperty<Stretch>(nameof(Stretch));
/// <summary>
/// The dependency property of icon URI.
/// </summary>
public static readonly DependencyProperty IconSourceProperty = DependencyObjectProxy.RegisterProperty<IconSource>(nameof(IconSource), OnIconUriChanged);
/// <summary>
/// The dependency property of icon width.
/// </summary>
public static readonly DependencyProperty IconWidthProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(IconWidth));
/// <summary>
/// The dependency property of icon height.
/// </summary>
public static readonly DependencyProperty IconHeightProperty = DependencyObjectProxy.RegisterDoubleProperty(nameof(IconHeight));
/// <summary>
/// The dependency property of icon margin.
/// </summary>
public static readonly DependencyProperty IconMarginProperty = DependencyObjectProxy.RegisterProperty<Thickness>(nameof(IconMargin));
/// <summary>
/// Initializes a new instance of the TextButton class.
/// </summary>
public TextButton()
{
InitializeComponent();
}
/// <summary>
/// Occurs when this control is clicked.
/// </summary>
public event RoutedEventHandler Click;
/// <summary>
/// Occurs when the text trimmed property value has changed.
/// </summary>
public event TypedEventHandler<TextButton, IsTextTrimmedChangedEventArgs> IsTextTrimmedChanged;
/// <summary>
/// Occurs when there is an error associated with image retrieval or format.
/// </summary>
public event ExceptionRoutedEventHandler ImageFailed;
/// <summary>
/// Occurs when the image source is downloaded and decoded with no failure.
/// </summary>
public event RoutedEventHandler ImageOpened;
/// <summary>
/// Gets or sets a value that indicates when the click event occurs, in terms of device behavior.
/// </summary>
public ClickMode ClickMode
{
get => OwnerButton.ClickMode;
set => OwnerButton.ClickMode = value;
}
/// <summary>
/// Gets or sets the command to invoke when this button is pressed.
/// </summary>
public ICommand Command
{
get => OwnerButton.Command;
set => OwnerButton.Command = value;
}
/// <summary>
/// Gets or sets the parameter to pass to the Command property.
/// </summary>
public object CommandParameter
{
get => OwnerButton.CommandParameter;
set => OwnerButton.CommandParameter = value;
}
/// <summary>
/// Gets a value that indicates whether a device pointer is located over this button control.
/// </summary>
public bool IsPointerOver => OwnerButton.IsPointerOver;
/// <summary>
/// Gets a value that indicates whether a ButtonBase is currently in a pressed state.
/// </summary>
public bool IsPressed => OwnerButton.IsPressed;
/// <summary>
/// Gets or sets the button template.
/// </summary>
public ControlTemplate ButtonTemplate
{
get => OwnerButton.Template;
set => OwnerButton.Template = value;
}
/// <summary>
/// Gets or sets the additional state.
/// </summary>
public string AdditionalState
{
get => (string)GetValue(AdditionalStateProperty);
set => SetValue(AdditionalStateProperty, value);
}
/// <summary>
/// Gets or sets the text.
/// </summary>
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
/// <summary>
/// Gets the collection of inline text elements.
/// </summary>
public InlineCollection Inlines => TextControl.Inlines;
/// <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 Orientation
{
get => (Orientation)GetValue(OrientationProperty);
set => SetValue(OrientationProperty, value);
}
/// <summary>
/// Gets or sets the contentn horizontal alignment.
/// </summary>
public HorizontalAlignment HorizontalItemAlignment
{
get => (HorizontalAlignment)GetValue(HorizontalItemAlignmentProperty);
set => SetValue(HorizontalItemAlignmentProperty, value);
}
/// <summary>
/// Gets or sets the contentn vertical alignment.
/// </summary>
public VerticalAlignment VerticalItemAlignment
{
get => (VerticalAlignment)GetValue(VerticalItemAlignmentProperty);
set => SetValue(VerticalItemAlignmentProperty, value);
}
/// <summary>
/// Gets or sets the margin of text.
/// </summary>
public Thickness TextMargin
{
get => (Thickness)GetValue(TextMarginProperty);
set => SetValue(TextMarginProperty, value);
}
/// <summary>
/// Gets or sets the text wrapping mode.
/// </summary>
public TextWrapping TextWrapping
{
get => (TextWrapping)GetValue(TextWrappingProperty);
set => SetValue(TextWrappingProperty, value);
}
/// <summary>
/// Gets or sets the text trimming mode.
/// </summary>
public TextTrimming TextTrimming
{
get => (TextTrimming)GetValue(TextTrimmingProperty);
set => SetValue(TextTrimmingProperty, value);
}
/// <summary>
/// Gets or sets the space.
/// </summary>
public double Spacing
{
get => (double)GetValue(SpacingProperty);
set => SetValue(SpacingProperty, value);
}
/// <summary>
/// Gets or sets the hover foreground.
/// </summary>
public Brush HoverForeground
{
get => (Brush)GetValue(HoverForegroundProperty);
set => SetValue(HoverForegroundProperty, value);
}
/// <summary>
/// Gets or sets the disabled foreground.
/// </summary>
public Brush DisabledForeground
{
get => (Brush)GetValue(DisabledForegroundProperty);
set => SetValue(DisabledForegroundProperty, value);
}
/// <summary>
/// Gets or sets the normal background.
/// </summary>
public Brush NormalBackground
{
get => (Brush)GetValue(NormalBackgroundProperty);
set => SetValue(NormalBackgroundProperty, value);
}
/// <summary>
/// Gets or sets the hover background.
/// </summary>
public Brush HoverBackground
{
get => (Brush)GetValue(HoverBackgroundProperty);
set => SetValue(HoverBackgroundProperty, value);
}
/// <summary>
/// Gets or sets the disabled background.
/// </summary>
public Brush DisabledBackground
{
get => (Brush)GetValue(DisabledBackgroundProperty);
set => SetValue(DisabledBackgroundProperty, value);
}
/// <summary>
/// Gets or sets the normal border brush.
/// </summary>
public Brush NormalBorderBrush
{
get => (Brush)GetValue(NormalBorderBrushProperty);
set => SetValue(NormalBorderBrushProperty, value);
}
/// <summary>
/// Gets or sets the hover border brush.
/// </summary>
public Brush HoverBorderBrush
{
get => (Brush)GetValue(HoverBorderBrushProperty);
set => SetValue(HoverBorderBrushProperty, value);
}
/// <summary>
/// Gets or sets the disabled border brush.
/// </summary>
public Brush DisabledBorderBrush
{
get => (Brush)GetValue(DisabledBorderBrushProperty);
set => SetValue(DisabledBorderBrushProperty, value);
}
/// <summary>
/// Gets or sets the normal border thickness.
/// </summary>
public Thickness NormalBorderThickness
{
get => (Thickness)GetValue(NormalBorderThicknessProperty);
set => SetValue(NormalBorderThicknessProperty, value);
}
/// <summary>
/// Gets or sets the hover border thickness.
/// </summary>
public Thickness HoverBorderThickness
{
get => (Thickness)GetValue(HoverBorderThicknessProperty);
set => SetValue(HoverBorderThicknessProperty, value);
}
/// <summary>
/// Gets or sets the disabled border thickness.
/// </summary>
public Thickness DisabledBorderThickness
{
get => (Thickness)GetValue(DisabledBorderThicknessProperty);
set => SetValue(DisabledBorderThicknessProperty, value);
}
/// <summary>
/// Gets or sets the opacity of the background panel when the state is disabled.
/// </summary>
public double DisabledPanelOpacity
{
get => (double)GetValue(DisabledPanelOpacityProperty);
set => SetValue(DisabledPanelOpacityProperty, value);
}
/// <summary>
/// Gets or sets the width of image.
/// </summary>
public double ImageWidth
{
get => (double)GetValue(ImageWidthProperty);
set => SetValue(ImageWidthProperty, value);
}
/// <summary>
/// Gets or sets the height of image.
/// </summary>
public double ImageHeight
{
get => (double)GetValue(ImageHeightProperty);
set => SetValue(ImageHeightProperty, value);
}
/// <summary>
/// Gets or sets the image source.
/// </summary>
public ImageSource ImageSource
{
get => (ImageSource)GetValue(ImageSourceProperty);
set => SetValue(ImageSourceProperty, value);
}
/// <summary>
/// Gets or sets the margin of image.
/// </summary>
public Thickness ImageMargin
{
get => (Thickness)GetValue(ImageMarginProperty);
set => SetValue(ImageMarginProperty, value);
}
/// <summary>
/// Gets or sets the corner radius of image.
/// </summary>
public CornerRadius ImageCornerRadius
{
get => (CornerRadius)GetValue(ImageCornerRadiusProperty);
set => SetValue(ImageCornerRadiusProperty, value);
}
/// <summary>
/// Gets or sets the stretch of image.
/// </summary>
public Stretch Stretch
{
get => (Stretch)GetValue(StretchProperty);
set => SetValue(StretchProperty, value);
}
/// <summary>
/// Gets or sets the width of icon.
/// </summary>
public double IconWidth
{
get => (double)GetValue(IconWidthProperty);
set => SetValue(IconWidthProperty, value);
}
/// <summary>
/// Gets or sets the height of icon.
/// </summary>
public double IconHeight
{
get => (double)GetValue(IconHeightProperty);
set => SetValue(IconHeightProperty, value);
}
/// <summary>
/// Gets or sets the margin of icon.
/// </summary>
public Thickness IconMargin
{
get => (Thickness)GetValue(IconMarginProperty);
set => SetValue(IconMarginProperty, value);
}
/// <summary>
/// Gets or sets the icon source.
/// </summary>
public IconSource IconSource
{
get => (IconSource)GetValue(IconSourceProperty);
set => SetValue(IconSourceProperty, value);
}
/// <summary>
/// Gets or sets the child before content.
/// </summary>
public UIElement BeforeContentChild
{
get => BeforeElement.Child;
set => BeforeElement.Child = value;
}
/// <summary>
/// Gets or sets the child after content.
/// </summary>
public UIElement AfterContentChild
{
get => AfterElement.Child;
set => AfterElement.Child = value;
}
/// <summary>
/// Gets or sets the child in normal state.
/// </summary>
public UIElement NormalChild
{
get => NormalPanel.Child;
set => NormalPanel.Child = value;
}
/// <summary>
/// Gets or sets the child in hover state.
/// </summary>
public UIElement HoverChild
{
get => HoverPanel.Child;
set => HoverPanel.Child = value;
}
/// <summary>
/// Registers a click event handler.
/// </summary>
/// <param name="click">The click event handler.</param>
/// <param name="options">The interceptor policy.</param>
/// <returns>The handler registered.</returns>
public RoutedEventHandler RegisterClick(RoutedEventHandler click, InterceptorPolicy options = null)
{
if (click == null) return null;
if (options == null)
{
Click += click;
return click;
}
var action = Interceptor.Action<object, RoutedEventArgs>((sender, ev) => click(sender, ev), options);
void h(object sender, RoutedEventArgs ev)
{
action(sender, ev);
}
Click += h;
return h;
}
/// <summary>
/// Transitions a control between two states, by requesting a new VisualState by name.
/// </summary>
/// <param name="name">The state to transition to.</param>
/// <returns>true if the control successfully transitions to the new state, or was already using that state; otherwise, false.</returns>
public bool GoToButtonState(string name)
=> VisualStateManager.GoToState(OwnerButton, name, true);
/// <summary>
/// Sets image.
/// </summary>
/// <param name="uri">The image URI.</param>
/// <returns>The image source.</returns>
public ImageSource SetImage(Uri uri)
=> ImageSource = new BitmapImage
{
UriSource = uri
};
/// <summary>
/// Sets font icon.
/// </summary>
/// <param name="glyph">The icon glyphl.</param>
/// <returns>The font icon source.</returns>
public FontIconSource SetFontIcon(string glyph)
{
if (string.IsNullOrWhiteSpace(glyph)) return null;
var icon = new FontIconSource
{
Glyph = glyph
};
IconSource = icon;
return icon;
}
/// <summary>
/// Sets font icon.
/// </summary>
/// <param name="glyph">The icon glyphl.</param>
/// <returns>The font icon source.</returns>
public FontIconSource SetFontIcon(char glyph)
{
var icon = new FontIconSource
{
Glyph = glyph.ToString()
};
IconSource = icon;
return icon;
}
/// <summary>
/// Sets font icon.
/// </summary>
/// <param name="symbol">The icon symbol.</param>
/// <returns>The font icon source.</returns>
public SymbolIconSource SetIcon(Symbol symbol)
{
var icon = new SymbolIconSource
{
Symbol = symbol
};
IconSource = icon;
return icon;
}
/// <summary>
/// Sets font icon.
/// </summary>
/// <param name="uri">The icon URI.</param>
/// <returns>The font icon source.</returns>
public BitmapIconSource SetIcon(Uri uri)
{
if (uri == null) return null;
var icon = new BitmapIconSource
{
UriSource = uri
};
IconSource = icon;
return icon;
}
private void Button_Click(object sender, RoutedEventArgs e)
=> Click?.Invoke(this, e);
private static void OnSpacingChanged(TextButton c, ChangeEventArgs<double> e, DependencyProperty p)
{
var i = double.IsNaN(e.NewValue) ? 0 : e.NewValue;
c.ImagePanel.Margin = c.IconControl.Margin = new Thickness(0, 0, i, 0);
}
private static void OnImageUriChanged(TextButton c, ChangeEventArgs<ImageSource> e, DependencyProperty p)
=> c.ImagePanel.Visibility = e.NewValue == null ? Visibility.Collapsed : Visibility.Visible;
private static void OnIconUriChanged(TextButton c, ChangeEventArgs<IconSource> e, DependencyProperty p)
=> c.IconControl.Visibility = e.NewValue == null ? Visibility.Collapsed : Visibility.Visible;
private void OwnerButton_PointerEntered(object sender, PointerRoutedEventArgs e)
{
NormalPanel.Visibility = Visibility.Collapsed;
HoverPanel.Visibility = Visibility.Visible;
}
private void OwnerButton_PointerExited(object sender, PointerRoutedEventArgs e)
{
NormalPanel.Visibility = Visibility.Visible;
HoverPanel.Visibility = Visibility.Collapsed;
}
private void ImageControl_ImageFailed(object sender, ExceptionRoutedEventArgs e)
=> ImageFailed?.Invoke(this, e);
private void ImageControl_ImageOpened(object sender, RoutedEventArgs e)
=> ImageOpened?.Invoke(this, e);
private void TextBlock_IsTextTrimmedChanged(TextBlock sender, IsTextTrimmedChangedEventArgs args)
=> IsTextTrimmedChanged?.Invoke(this, args);
}