您可以使用自定义渲染器来实现此功能:
对于安卓设备:
[assembly: ExportRenderer(typeof(Picker), typeof(CustomPickerRenderer))]
namespace App18.Droid
{
public class CustomPickerRenderer : PickerRenderer
{
private Context context;
public CustomPickerRenderer(Context context) : base(context)
{
this.context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (Control == null || e.NewElement == null) return;
//for example ,change the line to red:
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
Control.BackgroundTintList = ColorStateList.ValueOf(Color.Red);
else
Control.Background.SetColorFilter(Color.Red, PorterDuff.Mode.SrcAtop);
}
}
}
iOS:
[assembly: ExportRenderer(typeof(Picker), typeof(CustomPickerRenderer))]
namespace App18.iOS
{
public class CustomPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (Control == null || e.NewElement == null)
return;
Control.Layer.BorderWidth = 1;
Control.Layer.BorderColor = Color.Red.ToCGColor();
}
}
}
<StackLayout Orientation="Vertical" Spacing="0" HorizontalOptions="FillAndExpand">
<app1:DatePickerNoLine x:Name="datePickerScheduleDate" Unfocused="ScheduleCriteriaChanged" VerticalOptions="Center" HorizontalOptions="FillAndExpand" FontSize="Subtitle" BackgroundColor="LightBlue"/>
<BoxView x:Name="BoxdatePickerScheduleDate" HeightRequest="1" HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand" Color="Black" WidthRequest="{Binding WidthRequest, Source={x:Reference datePickerScheduleDate}}" />
</StackLayout>
Use the custom renderer to remove the underline that comes with picker.
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
this.Control.Text = Element.Date.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
Control.Layer.BackgroundColor = Color.White.ToCGColor();
Control.BorderStyle = UITextBorderStyle.None;
Control.Layer.BorderColor = Color.Transparent.ToCGColor();
Control.LeftView = new UIKit.UIView(new CGRect(0, 0, 10, 0));
Control.LeftViewMode = UIKit.UITextFieldViewMode.Always;
UITextField entry = Control;
UIDatePicker picker = (UIDatePicker)entry.InputView;
picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels;
}
}
BorderColor
我们没有其他的东西吗? - R15