Platform | Version |
---|---|
Android | MonoAndroid90+ |
iOS | Xamarin.iOS10 |
.NET Standard | 2.0 |
This library can be used in Xamarin.iOS, Xamarin.Android or Xamarin.Forms projects
In the Android project's MainLauncher or any Activity that is launched, this library must be initialized in the OnCreate method:
protected override void OnCreate(Bundle savedInstanceState)
{
//...
base.OnCreate(savedInstanceState);
Xamarin.DateTimePopups.Platform.Init(this, savedInstanceState); // add this line to your code, it may also be called: bundle
//...
}
You can set the function to get the current UIView
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Xamarin.DateTimePopups.Platform.Init(()=> Xamarin.Essentials.Platform.GetCurrentUIViewController()?.View);
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
using System;
using Xamarin.Forms;
using Xamarin.DateTimePopups;
namespace Sample.Views
{
public partial class HomePage : ContentPage
{
public HomePage()
=> InitializeComponent();
async void DateButton_Clicked(System.Object sender, System.EventArgs e)
{
DateTime? date = await DateTimePopups.PickDateAsync();
ResultLabel.Text = date.ToString();
}
async void TimeButton_Clicked(System.Object sender, System.EventArgs e)
{
TimeSpan? date = await DateTimePopups.PickTimeAsync();
ResultLabel.Text = date.ToString();
}
}
}
iOS (Date) | Android (Date) | iOS (Time) | Android (Time) |
---|---|---|---|