Material Design Icons
Hans Karlsen (talk | contribs) No edit summary |
(Automatically adding template at the end of the page.) |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
In | 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 | 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). | |||
You must | |||
There are new hooks on ViewModelWPFUserControl: | There are new hooks on ViewModelWPFUserControl: | ||
Eco.ViewModel.WPF.ViewModelWPFUserControl.IconFontFamilyResourceName = "materialdesigniconsfont"; | |||
Eco.ViewModel.WPF.ViewModelWPFUserControl.IconFontIconNameResolverInstall(IconNameResolver); | |||
Eco.ViewModel.WPF.ViewModelWPFUserControl.IconFontIconNameResolverInstall(IconNameResolver); | |||
The IconNameResolver must take a named icon and return the correct character. | The IconNameResolver must take a named icon and return the correct character. | ||
<pre> | <pre> | ||
Line 51: | Line 47: | ||
return "\ue87e";// System.Text.Encoding.UTF8.GetString(bytes); | return "\ue87e";// System.Text.Encoding.UTF8.GetString(bytes); | ||
} | }</pre> | ||
</pre> | |||
==== Turnkey ==== | |||
There's built-in support for using the Material design icon pack in Turnkey. | |||
==== Icons in WPF ==== | |||
[[File:Image of Icons in WPF.png|left|frameless|598x598px]] | |||
[[Category:MDriven Designer]] | |||
{{Edited|July|12|2024}} |
Latest revision as of 15:37, 10 February 2024
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