Jason の回答を詳しく説明するために、UIPickerView をカスタムの日付ピッカーとして使用するコード サンプルを次に示します。それが誰かを助けることを願っています。
UIPickerView datePicker = new UIPickerView ();
var mod = new DatePickerDataModel ();
datePicker.Model = mod;
mod.ValueChanged += (object sender, EventArgs e) => {
_selectedDate = mod.SelectedItem;
};
class DatePickerDataModel : UIPickerViewModel
{
public event EventHandler<EventArgs> ValueChanged;
public List<DateTime> Items { get; private set; }
public DateTime SelectedItem {
get { return Items [selectedIndex]; }
}
int selectedIndex = 0;
public DatePickerDataModel ()
{
var items = new List<DateTime> ();
for (int i = 0; i < 14; i++) {
items.Add (DateTime.Now.Subtract (TimeSpan.FromDays (i)));
}
Items = items;
}
public override nint GetRowsInComponent (UIPickerView picker, nint component)
{
return Items.Count;
}
public override nint GetComponentCount (UIPickerView picker)
{
return 1;
}
public override void Selected (UIPickerView picker, nint row, nint component)
{
selectedIndex = (int)row;
ValueChanged?.Invoke(this, EventArgs.Empty());
}
public override string GetTitle (UIPickerView pickerView, nint row, nint component)
{
var t = Items [(int)row];
var m = t.ToString ("MMM");
var d = t.ToString ("ddd");
return $"{d} {m} {t.Day}";
}
public override nfloat GetRowHeight (UIPickerView picker, nint component)
{
return 44;
}
}