-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaterialIcon.cs
55 lines (43 loc) · 1.97 KB
/
MaterialIcon.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Material.Icons;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace Material.Icons.UNO;
public partial class MaterialIcon : Control {
public MaterialIcon() {
this.DefaultStyleKey = typeof(MaterialIcon);
// ..OverrideMetadata(typeof(MaterialIcon), new FrameworkPropertyMetadata(typeof(MaterialIcon)));
}
public static readonly DependencyProperty KindProperty
= DependencyProperty.Register(nameof(Kind), typeof(MaterialIconKind), typeof(MaterialIcon),
new PropertyMetadata(default(MaterialIconKind), KindPropertyChangedCallback));
private static void KindPropertyChangedCallback(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
=> ((MaterialIcon) dependencyObject).UpdateData();
/// <summary>
/// Gets or sets the icon to display.
/// </summary>
public MaterialIconKind Kind {
get => (MaterialIconKind) GetValue(KindProperty);
set => SetValue(KindProperty, value);
}
private static readonly DependencyProperty DataProperty
= DependencyProperty.Register(nameof(Data), typeof(string), typeof(MaterialIcon), new PropertyMetadata(""));
/// <summary>
/// Gets the icon path data for the current <see cref="Kind"/>.
/// </summary>
[TypeConverter(typeof(GeometryConverter))]
public string? Data {
get => (string?) GetValue(DataProperty);
private set => SetValue(DataProperty, value);
}
protected override void OnApplyTemplate() {
base.OnApplyTemplate();
UpdateData();
}
private void UpdateData() {
Data = MaterialIconDataProvider.GetData(Kind);
}
}