Material Design Icons
No edit summary |
m ((username removed) (log details removed): Moving to Documentation namespace) |
(No difference)
|
Revision as of 20:50, 20 December 2023
In the WECPOFLogic assembly, we have included the MaterialIcons-Regular.ttf (added as Resource) and MaterialIcons-Regular.codepoints (added as Embedded Resource).
We then have a font family defined like this:
<FontFamily x:Key="materialdesigniconsfont">pack://application:,,,/WECPOFLogic;component/Fonts/#Material Icons</FontFamily>
If you have that row in your WPF-application App.Resources, you can use FontFamily={StaticResource materialdesigniconsfont} in xaml.
You must use the character code per icon (the complete list is in MaterialIcons-Regular.codepoints).
There are new hooks on ViewModelWPFUserControl:
Eco.ViewModel.WPF.ViewModelWPFUserControl.IconFontFamilyResourceName = "materialdesigniconsfont";
Eco.ViewModel.WPF.ViewModelWPFUserControl.IconFontIconNameResolverInstall(IconNameResolver);
The IconNameResolver must take a named icon and return the correct character.
public static Dictionary<string, string> IconNameToValueDict { get; private set; } public static string IconNameResolver(string name) { if (IconNameToValueDict == null) { IconNameToValueDict = new Dictionary<string, string>(); var stream = typeof(WECPOFTabBased).Assembly.GetManifestResourceStream(typeof(WECPOFTabBased).Assembly.GetName().Name + "." + "Fonts.MaterialIcons-Regular.codepoints"); using (var sr = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8)) { string content = sr.ReadToEnd(); var lines = content.Split('\n'); foreach (var line in lines) { var parts = line.Split(' '); if (parts.Length == 2) { if (!IconNameToValueDict.ContainsKey(parts[0])) { var c = (char)int.Parse(parts[1], System.Globalization.NumberStyles.HexNumber); IconNameToValueDict.Add(parts[0], c.ToString()); } } } } } if (IconNameToValueDict.TryGetValue(name, out var value)) return value; return "\ue87e";// System.Text.Encoding.UTF8.GetString(bytes); }
Turnkey
There's built-in support for using the Material design icon pack in Turnkey.
Icons in WPF
This page was edited more than 11 months ago on 02/10/2024. What links here