Xamarin表单开关控制器宽度更改

时间:2018-05-23 07:26:39

标签: xamarin.forms

如何更改xamarin表格开关中的开关宽度? enter image description here

尝试向android添加渲染类,但无法找到方法。

enter image description here

------- 这是android中的Render类

[assembly:ExportRenderer(typeof(ExtendedSwitch),typeof(ExtendedSwitchRenderer))]

命名空间Common.Droid.Renderers {     public class ExtendedSwitchRenderer:SwitchRenderer     {         public ExtendedSwitchRenderer(Context context)             :base(context)         {

    }

    protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
    {
        base.OnElementChanged(e);

        if (Control != null && e.NewElement != null)
        {
            var element = (ExtendedSwitch) e.NewElement;
            Control.TextOn = element.YesText ?? string.Empty;
            Control.TextOff = element.NoText ?? string.Empty;
        }
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        Control.SwitchMinWidth = 300;
        base.OnElementPropertyChanged(sender, e);

        if (e.PropertyName == ExtendedSwitch.YesTextProperty.PropertyName ||
            e.PropertyName == ExtendedSwitch.NoTextProperty.PropertyName)
        {
            var element = (ExtendedSwitch) Element;
            Control.TextOn = element.YesText ?? string.Empty;
            Control.TextOff = element.NoText ?? string.Empty;
        }
        Control.SwitchMinWidth = 300;
    }
}

}

0 个答案:

没有答案