-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathIconAndText.cs
More file actions
85 lines (71 loc) · 2.73 KB
/
IconAndText.cs
File metadata and controls
85 lines (71 loc) · 2.73 KB
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
using iNKORE.UI.WPF.Controls;
using iNKORE.UI.WPF.Modern.Common.IconKeys;
using System.Windows;
using System.Windows.Controls;
namespace iNKORE.UI.WPF.Modern.Controls
{
public class IconAndText : ContentControl
{
private FontIcon _fontIcon;
static IconAndText()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(IconAndText), new FrameworkPropertyMetadata(typeof(IconAndText)));
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_fontIcon = GetTemplateChild("Icon") as FontIcon;
UpdateIconElement();
}
#region Properties
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register(
nameof(Icon),
typeof(FontIconData?),
typeof(IconAndText),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure,
OnIconChanged
)
);
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is IconAndText iconAndText)
{
iconAndText.UpdateIconElement();
}
}
private void UpdateIconElement()
{
if (_fontIcon != null)
{
_fontIcon.Icon = Icon;
}
}
public FontIconData? Icon
{
get { return (FontIconData?)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}
public static readonly DependencyProperty SpacingProperty = SimpleStackPanel.SpacingProperty.AddOwner(typeof(IconAndText), new PropertyMetadata(6d));
public double Spacing
{
get { return (double)GetValue(SpacingProperty); }
set { SetValue(SpacingProperty, value); }
}
public static readonly DependencyProperty OrientationProperty = SimpleStackPanel.OrientationProperty.AddOwner(typeof(IconAndText), new PropertyMetadata(Orientation.Horizontal));
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
set { SetValue(OrientationProperty, value); }
}
public static readonly DependencyProperty IconSizeProperty = DependencyProperty.Register(nameof(IconSize), typeof(double), typeof(IconAndText), new PropertyMetadata(16d));
public double IconSize
{
get { return (double)GetValue(IconSizeProperty); }
set { SetValue(IconSizeProperty, value); }
}
#endregion
}
}