/
PackIconBootstrapIcons.cs
76 lines (69 loc) · 2.66 KB
/
PackIconBootstrapIcons.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
using System;
using System.Collections.Generic;
#if (NETFX_CORE || WINDOWS_UWP)
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
#else
using System.Windows;
#endif
namespace MahApps.Metro.IconPacks
{
/// <summary>
/// Bootstrap Icons are licensed under the [MIT license](<see><cref>https://github.com/twbs/icons?tab=MIT-1-ov-file#readme</cref></see>).
/// Contributions, corrections and requests can be made on GitHub <see><cref>https://github.com/twbs/icons</cref></see>.
/// </summary>
[MetaData("Bootstrap Icons", "https://icons.getbootstrap.com/", "https://github.com/twbs/icons?tab=MIT-1-ov-file#readme")]
public class PackIconBootstrapIcons : PackIconControlBase
{
public static readonly DependencyProperty KindProperty
= DependencyProperty.Register(nameof(Kind), typeof(PackIconBootstrapIconsKind), typeof(PackIconBootstrapIcons), new PropertyMetadata(default(PackIconBootstrapIconsKind), KindPropertyChangedCallback));
private static void KindPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue)
{
((PackIconBootstrapIcons)dependencyObject).UpdateData();
}
}
/// <summary>
/// Gets or sets the icon to display.
/// </summary>
public PackIconBootstrapIconsKind Kind
{
get { return (PackIconBootstrapIconsKind)GetValue(KindProperty); }
set { SetValue(KindProperty, value); }
}
#if !(NETFX_CORE || WINDOWS_UWP)
static PackIconBootstrapIcons()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PackIconBootstrapIcons), new FrameworkPropertyMetadata(typeof(PackIconBootstrapIcons)));
}
#endif
public PackIconBootstrapIcons()
{
#if NETFX_CORE || WINDOWS_UWP
this.DefaultStyleKey = typeof(PackIconBootstrapIcons);
#endif
}
protected override void SetKind<TKind>(TKind iconKind)
{
#if NETFX_CORE || WINDOWS_UWP
BindingOperations.SetBinding(this, PackIconBootstrapIcons.KindProperty, new Binding() { Source = iconKind, Mode = BindingMode.OneTime });
#else
this.SetCurrentValue(KindProperty, iconKind);
#endif
}
protected override void UpdateData()
{
if (Kind != default(PackIconBootstrapIconsKind))
{
string data = null;
PackIconBootstrapIconsDataFactory.DataIndex.Value?.TryGetValue(Kind, out data);
this.Data = data;
}
else
{
this.Data = null;
}
}
}
}