@@ -9,28 +9,58 @@ public partial class IconsPage : ContentPage
99{
1010 Dictionary < string , string > glyphs ;
1111 private Action < PxFontIcon > updateIcon ;
12- PxFontIcon selectedFontIcon = new PxFontIcon { FontFamily = "FontAwesomeBrands" , Glyph = FontAwesomeBrands . FontAwesomeAlt } ;
12+ Type selectedFontFamilyType = FontData . FontFamily [ nameof ( FontType . FontAwesomeBrands ) ] ;
13+ PxFontIcon selectedFontIcon = new PxFontIcon { FontFamily = nameof ( FontType . FontAwesomeBrands ) , Glyph = FontAwesomeBrands . FontAwesomeAlt } ;
14+ FontImageSource ? selectedFontImageSource = default ;
1315
1416 public IconsPage ( )
1517 {
1618 InitializeComponent ( ) ;
1719 LoadIcons ( ) ;
1820 Debug . WriteLine ( "Loading icons ..." ) ;
21+ this . BindingContext = this ;
1922 }
2023
2124 public IconsPage ( Action < PxFontIcon > callback ) : this ( )
2225 {
2326 this . updateIcon = callback ;
2427 }
2528
29+ List < string > fontFamilyNames = FontData . FontFamily . Keys . ToList ( ) ;
30+ public List < string > FontFamilyNames { get => fontFamilyNames ; }
31+
32+ string selectedFontFamilyName = nameof ( FontType . FontAwesomeBrands ) ;
33+ public string SelectedFontFamilyName
34+ {
35+ get => selectedFontFamilyName ;
36+ set
37+ {
38+ if ( selectedFontFamilyName != value )
39+ {
40+ selectedFontFamilyName = value ;
41+ selectedFontFamilyType = FontData . FontFamily [ value ] ;
42+ //glyphs = FontData.GetGlyphs(selectedFontFamilyType);
43+ flexLayout . Children . Clear ( ) ;
44+ LoadIcons ( ) ;
45+ OnPropertyChanged ( ) ;
46+ }
47+ }
48+ }
49+
2650 void OnImageButtonClicked ( object ? sender , EventArgs e )
2751 {
2852 if ( sender is ImageButton imageButton && imageButton . Source is FontImageSource fontImageSource )
2953 {
3054 var glyph = glyphs . FirstOrDefault ( x => x . Value == fontImageSource . Glyph ) ;
3155 Debug . WriteLine ( $ "ImageButton clicked with Glyph: { glyph . Key } ") ;
3256 selectedIcon . Text = $ "The selected icon is { glyph . Key } .";
33- selectedFontIcon = new PxFontIcon { FontFamily = "FontAwesomeBrands" , Glyph = glyph . Value } ;
57+ selectedFontIcon = new PxFontIcon { FontFamily = selectedFontFamilyName , Glyph = glyph . Value } ;
58+ if ( selectedFontImageSource != null )
59+ {
60+ selectedFontImageSource . Color = Microsoft . Maui . Graphics . Colors . Black ;
61+ }
62+ selectedFontImageSource = fontImageSource ;
63+ fontImageSource . Color = ( Color ) Application . Current . Resources [ "Primary" ] ;
3464 }
3565 else
3666 {
@@ -40,7 +70,7 @@ void OnImageButtonClicked(object? sender, EventArgs e)
4070
4171 async Task LoadIcons ( )
4272 {
43- glyphs = FontData . GetGlyphs ( typeof ( FontAwesomeBrands ) ) ;
73+ glyphs = FontData . GetGlyphs ( selectedFontFamilyType ) ;
4474
4575 await Task . Run ( async ( ) =>
4676 {
@@ -51,7 +81,7 @@ await Task.Run(async () =>
5181 {
5282 Source = new FontImageSource
5383 {
54- FontFamily = "FontAwesomeBrands" ,
84+ FontFamily = selectedFontFamilyName ,
5585 Glyph = glyph . Value ,
5686 Size = 32 ,
5787 Color = Microsoft . Maui . Graphics . Colors . Black
0 commit comments