Last active
April 21, 2019 08:36
-
-
Save darxis/80de2f3213546d6dbb034fc06dd5a255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PackIconControl : ContentControl | |
{ | |
public PackIconControl() | |
{ | |
SizeChanged += OnSizeChanged; | |
} | |
public static readonly DependencyProperty PackIconKindProperty = | |
DependencyProperty.Register(nameof(PackIconKind), typeof(object), typeof(PackIconControl), | |
new PropertyMetadata(default(object), PackIconKindPropertyChangedCallback)); | |
private static void PackIconKindPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) | |
{ | |
PackIconBase newContent; | |
switch (dependencyPropertyChangedEventArgs.NewValue) | |
{ | |
case PackIconEntypoKind kind: | |
newContent = new PackIconEntypo { Kind = kind }; | |
break; | |
case PackIconFontAwesomeKind kind: | |
newContent = new PackIconFontAwesome { Kind = kind }; | |
break; | |
case PackIconMaterialKind kind: | |
newContent = new PackIconMaterial { Kind = kind }; | |
break; | |
case PackIconMaterialLightKind kind: | |
newContent = new PackIconMaterialLight { Kind = kind }; | |
break; | |
case PackIconModernKind kind: | |
newContent = new PackIconModern { Kind = kind }; | |
break; | |
case PackIconOcticonsKind kind: | |
newContent = new PackIconOcticons { Kind = kind }; | |
break; | |
case PackIconSimpleIconsKind kind: | |
newContent = new PackIconSimpleIcons { Kind = kind }; | |
break; | |
default: | |
newContent = null; | |
break; | |
} | |
var control = (PackIconControl)dependencyObject; | |
if (newContent != null) | |
{ | |
newContent.Width = control.Width; | |
newContent.Height = control.Height; | |
} | |
control.Content = newContent; | |
} | |
public object PackIconKind | |
{ | |
get => GetValue(PackIconKindProperty); | |
set => SetValue(PackIconKindProperty, value); | |
} | |
private void OnSizeChanged(object sender, SizeChangedEventArgs e) | |
{ | |
if (Content is PackIconBase content) | |
{ | |
content.Width = Width; | |
content.Height = Height; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment