I'm trying to implement a custom control that derives from DatePicker. This control will have android and iOS renderers. I need to add FontSize property for this control which I will use in renderer classes.
Here is my implementation of the FontSize property:
public static BindableProperty FontSizeProperty = BindableProperty.Create<ExDatePicker, double>(o => o.FontSize, 16d, propertyChanged: OnFontSizeChanged);
public double FontSize
{
get { return (double)GetValue(FontSizeProperty); }
set { SetValue(FontSizeProperty, value); }
}
private static void OnFontSizeChanged(BindableObject bindable, double oldvalue, double newvalue)
{
var control = bindable as ExDatePicker;
if (control != null)
{
control.FontSize = newvalue;
}
}
What I need is ability to use this property in the same way as native FontSize properties works, i.e. I need to be able to set something like
FontSize="Small"
in xaml code. Is it possible?
EDIT: In xamarin forms one can use FontSize="Small" to set the device specific font size for different platforms. This autmagically converts the "Small" string into the double using
Device.GetNamedSize(NamedSize.Small, typeof(ExtednedDatePicker))
I don't know how to add this autoconversion for user created FontSize not in Xamarin Forms library
OnFontSizeChanged
method try identify if it is astring
ordouble
and if it is a string use aswitch statement
to set the size? – User1