private IEnumerable <IconDescription> ToIconDescription(ThemifyIconsIcon icon, string filter) { var memberInfo = typeof(ThemifyIconsIcon).GetMember(icon.ToString()).FirstOrDefault(); if (memberInfo == null) { yield break; } foreach (var cat in memberInfo.GetCustomAttributes(typeof(IconCategoryAttribute), false).Cast <IconCategoryAttribute>()) { var desc = memberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast <DescriptionAttribute>().First(); var id = memberInfo.GetCustomAttributes(typeof(IconIdAttribute), false).Cast <IconIdAttribute>().FirstOrDefault(); if (!string.IsNullOrEmpty(filter) && !( desc.Description.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) > -1 || icon.ToString().IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) > -1) ) { continue; } yield return(new IconDescription { Category = cat.Category, Description = desc.Description, Icon = icon, Id = id?.Id }); } }
/// <summary> /// Creates a new System.Windows.Media.ImageSource of a specified ThemifyIconsIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The ThemifyIcons icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <returns>A new System.Windows.Media.ImageSource</returns> public static ImageSource CreateImageSource(ThemifyIconsIcon icon, Brush foregroundBrush, double emSize = 100) { var charIcon = char.ConvertFromUtf32((int)icon); var visual = new DrawingVisual(); using (var drawingContext = visual.RenderOpen()) { drawingContext.DrawText( new FormattedText(charIcon, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, ThemifyIconsTypeface, emSize, foregroundBrush) { TextAlignment = TextAlignment.Center }, new Point(0, 0)); } return(new DrawingImage(visual.Drawing)); }
private static void ContentChanged(DependencyObject sender, DependencyPropertyChangedEventArgs evt) { // If target is not a ContenControl just ignore: Themify.Content property can only be set on a ContentControl element if (!(sender is ContentControl)) { return; } ContentControl target = (ContentControl)sender; // If value is not a ThemifyIconsIcon just ignore: Themify.Content property can only be set to a ThemifyIconsIcon value if (!(evt.NewValue is ThemifyIconsIcon)) { return; } ThemifyIconsIcon symbolIcon = (ThemifyIconsIcon)evt.NewValue; int symbolCode = (int)symbolIcon; char symbolChar = (char)symbolCode; target.FontFamily = ThemifyIconsFontFamily; target.Content = symbolChar; }
/// <summary> /// Sets the content of a ContentControl expressed as a ThemifyIcons icon. This will cause the content to be redrawn. /// </summary> /// <param name="target">The ContentControl where to set the content</param> /// <param name="value">ThemifyIcons icon to set as content</param> public static void SetContent(DependencyObject target, ThemifyIconsIcon value) { target.SetValue(ContentProperty, value); }