Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit ca19ec9

Browse files
Add custom font family to label and assistive label
1 parent 9523eec commit ca19ec9

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

MaterialDesignControls.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata minClientVersion="2.8.1">
44
<id>Plugin.MaterialDesignControls</id>
5-
<version>1.10.2</version>
5+
<version>1.10.3</version>
66
<title>MaterialDesignControls Plugin for Xamarin Forms</title>
77
<authors>Horus</authors>
88
<owners>AgustinBonillaHorus</owners>

example/ExampleMaterialDesignControls/Pages/MaterialEntryPage.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
<material:MaterialEntry.CustomTrailingIcon>
3535
<ffimageloadingsvg:SvgCachedImage Source="resource://ExampleMaterialDesignControls.Resources.Svg.ic_help_b.svg"/>
3636
</material:MaterialEntry.CustomTrailingIcon>
37+
<material:MaterialEntry.FontFamily>
38+
<OnPlatform x:TypeArguments="x:String">
39+
<OnPlatform.Android>monospace</OnPlatform.Android>
40+
<OnPlatform.iOS>MarkerFelt-Thin</OnPlatform.iOS>
41+
</OnPlatform>
42+
</material:MaterialEntry.FontFamily>
43+
<material:MaterialEntry.LabelFontFamily>
44+
<OnPlatform x:TypeArguments="x:String">
45+
<OnPlatform.Android>sans-serif-black</OnPlatform.Android>
46+
<OnPlatform.iOS>Arial Rounded MT Bold</OnPlatform.iOS>
47+
</OnPlatform>
48+
</material:MaterialEntry.LabelFontFamily>
3749
</material:MaterialEntry>
3850

3951
<material:MaterialButton Text="Save" Icon="save.png" Command="{Binding TapCommand}" VerticalOptions="EndAndExpand" Margin="0,0,0,20" />

src/MaterialDesignControls/Controls/BaseMaterialFieldControl.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ public double LabelSize
183183
set { SetValue(LabelSizeProperty, value); }
184184
}
185185

186+
public static readonly BindableProperty LabelFontFamilyProperty =
187+
BindableProperty.Create(nameof(LabelFontFamily), typeof(string), typeof(BaseMaterialFieldControl), defaultValue: null);
188+
189+
public string LabelFontFamily
190+
{
191+
get { return (string)GetValue(LabelFontFamilyProperty); }
192+
set { SetValue(LabelFontFamilyProperty, value); }
193+
}
194+
186195
public static readonly BindableProperty LabelMarginProperty =
187196
BindableProperty.Create(nameof(LabelMargin), typeof(Thickness), typeof(BaseMaterialFieldControl), defaultValue: new Thickness(14, 0, 14, 2));
188197

@@ -223,6 +232,15 @@ public double AssistiveSize
223232
set { SetValue(AssistiveSizeProperty, value); }
224233
}
225234

235+
public static readonly BindableProperty AssistiveFontFamilyProperty =
236+
BindableProperty.Create(nameof(AssistiveFontFamily), typeof(string), typeof(BaseMaterialFieldControl), defaultValue: null);
237+
238+
public string AssistiveFontFamily
239+
{
240+
get { return (string)GetValue(AssistiveFontFamilyProperty); }
241+
set { SetValue(AssistiveFontFamilyProperty, value); }
242+
}
243+
226244
public static readonly BindableProperty AssistiveMarginProperty =
227245
BindableProperty.Create(nameof(AssistiveMargin), typeof(Thickness), typeof(BaseMaterialFieldControl), defaultValue: new Thickness(14, 2, 14, 0));
228246

@@ -458,9 +476,23 @@ protected void UpdateLayout(string propertyName, Label lblLabel, Label lblAssist
458476
SetFontSize();
459477
break;
460478
case nameof(FontFamily):
479+
case nameof(LabelFontFamily):
480+
case nameof(AssistiveFontFamily):
461481
SetFontFamily();
462-
lblLabel.FontFamily = FontFamily;
463-
lblAssistive.FontFamily = FontFamily;
482+
483+
if (LabelFontFamily != null)
484+
lblLabel.FontFamily = LabelFontFamily;
485+
else if (LabelFontFamily == null && FontFamily != null)
486+
lblLabel.FontFamily = FontFamily;
487+
488+
if (AssistiveFontFamily != null)
489+
lblAssistive.FontFamily = AssistiveFontFamily;
490+
else if (AssistiveFontFamily == null && FontFamily != null)
491+
lblAssistive.FontFamily = FontFamily;
492+
493+
494+
//lblLabel.FontFamily = FontFamily;
495+
//lblAssistive.FontFamily = FontFamily;
464496
break;
465497
case nameof(Placeholder):
466498
SetPlaceholder();

0 commit comments

Comments
 (0)