Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to get value of custom control's bindable property from custom renderer?

$
0
0

I'm still learning how to write a custom control using custom renderer. Right now I'm stuck at getting the value of a bindable property in a custom control from a custom renderer. Could someone help me with this?
Thanks

Custom Control for TimePicker:

public class CustomTimePicker: TimePicker
{
    public static readonly BindableProperty CustomFontSizeProperty =
        BindableProperty.Create("CustomFontSize", typeof(string), typeof (CustomTimePicker), defaultBindingMode: BindingMode.OneWay);
}

Custom Renderer for TimePicker:

[assembly: ExportRenderer(typeof(CustomTimePicker), typeof(CustomTimePickerRenderer))]
namespace MYNS.Mobile.Droid
{
    public class CustomTimePickerRenderer : TimePickerRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.TimePicker> e) {
            base.OnElementChanged(e);
            if (e.OldElement == null) {
                Control.SetTextSize(Android.Util.ComplexUnitType.Sp, 11.0f); 
                // right now the font size is hard coded. Id like to get the value from the custom control somehow. 
                // I tried Element but the property is not exposed via that
            }
        }
    }
} 

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>