我的堆栈由Xamarin iOS和MVVMCross组成。对于日期选择器,我使用此程序包:
https://github.com/alexsorokoletov/Xamarin.iOS.DatePickerDialog
我想使用最小和最大日期,但这不起作用。我试图调用对话框show方法,如下所示:
var startingTime = DateTime.Now;
DateTime min = DateTime.Now.AddDays(-10);
DateTime max = DateTime.Now.AddDays(10);
var dialog = new DT.iOS.DatePickerDialog.DatePickerDialog();
dialog.Show("Choose time", "Done", "Cancel", UIDatePickerMode.Date, (dt) =>
{
string selectedDate = dt.ToString();
}, startingTime, minimumDate, maximumDate);
我试图这样声明最小和最大日期(使用来自MvvmCross.Platforms.Ios的WithKind:]
var minimumDate = new DateTime(2019, 10, 1).WithKind(DateTimeKind.Local);
var maximumDate = new DateTime(2019, 11, 1).WithKind(DateTimeKind.Local);
但是似乎没有任何作用。我没有其他想法了。非常感谢您的帮助!谢谢嘉豪!
我认为参数min
和max
的顺序应该是相反的。所以首先是max
,其次是min
:
var startingTime = DateTime.Now;
DateTime min = DateTime.Now.AddDays(-10);
DateTime max = DateTime.Now.AddDays(10);
var dialog = new DT.iOS.DatePickerDialog.DatePickerDialog();
dialog.Show("Choose time", "Done", "Cancel", UIDatePickerMode.Date, (dt) =>
{
string selectedDate = dt.ToString();
}, startingTime, max, min);