Hi,
I am using a BindablePicker as given here . However, the displayed selected item name font size by default is larger than what is required in my design. So, I want to add two more properties to this picker so that the displayed text, which happens to be the DisplayMemberPath can have desired font size and font family.
I have added them in the BindablePicker control as :
public static readonly BindableProperty FontFamilyProperty =
BindableProperty.Create("FontFamily", typeof(string), typeof(BindablePicker),string.Empty,BindingMode.OneWay);
public string FontFamily
{
get
{
return (string)GetValue(FontFamilyProperty);
}
set
{
SetValue(FontFamilyProperty, value);
}
}
public static readonly BindableProperty FontSizeProperty =
BindableProperty.Create("FontSize",
typeof(float),
typeof(BindablePicker),15f);
public float FontSize
{
get
{
return (float)this.GetValue(FontSizeProperty);
}
set
{
this.SetValue(FontSizeProperty, value);
}
}
How do I write an android and an iOS renderer to achieve the requirement ?
Related to this issue,
I just tried setting the control's font size and family in the renderer (not as mentioned in the XAML, but hard coded) as :
Android:
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Picker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Typeface = Typeface.CreateFromAsset(Context.Assets, "Roboto-Medium.ttf");
Control.TextSize = 16;
}
}
iOS:
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Picker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Font = UIFont.SystemFontOfSize(16);
Control.Font = UIFont.FromName("Roboto-Regular", 16f);
}
}
This although creates not much of an issue in iOS, the pop-up dialog displayed in the Android device is not proper.
I have attached the android screenshots here.
I want the picker pop up to be as the default pop up, but the font size and family set as in the custom renderer.
How can I achieve this ?
Any help would be greatly appreciated.