internal static void UpdatePicker(this MauiPicker platformPicker, IPicker picker, int?newSelectedIndex = null) { var selectedIndex = newSelectedIndex ?? picker.SelectedIndex; // Revert to placeholder/title if nothing selected platformPicker.Text = selectedIndex == -1 ? (picker.Title ?? string.Empty) : picker.GetItem(selectedIndex); var pickerView = platformPicker.UIPickerView; pickerView?.ReloadAllComponents(); if (picker.GetCount() == 0) { return; } picker.SelectedIndex = selectedIndex; if (pickerView?.Model is PickerSource source) { source.SelectedIndex = selectedIndex; } pickerView?.Select(Math.Max(selectedIndex, 0), 0, true); }
internal static void UpdatePicker(this Entry platformPicker, IPicker picker) { if (picker.SelectedIndex == -1 || picker.SelectedIndex >= picker.GetCount()) { platformPicker.Text = string.Empty; } else { platformPicker.Text = picker.GetItem(picker.SelectedIndex); } }
internal static void UpdatePicker(this MauiPicker nativePicker, IPicker picker) { nativePicker.Hint = picker.Title; if (picker.SelectedIndex == -1 || picker.SelectedIndex >= picker.GetCount()) { nativePicker.Text = null; } else { nativePicker.Text = picker.GetItem(picker.SelectedIndex); } }
internal static void UpdatePicker(this MauiPicker nativePicker, IPicker picker) { var selectedIndex = picker.SelectedIndex; nativePicker.Text = selectedIndex == -1 ? "" : picker.GetItem(selectedIndex); var pickerView = nativePicker.UIPickerView; pickerView?.ReloadAllComponents(); if (picker.GetCount() == 0) { return; } nativePicker.SetSelectedIndex(picker, selectedIndex); }
public override string GetTitle(UIPickerView picker, nint row, nint component) => _virtualView?.GetItem((int)row) ?? "";
public static string[] GetItemsAsArray(this IPicker picker) => Enumerable.Range(0, picker.GetCount()).Select(i => picker.GetItem(i)).ToArray();
public static List <string> GetItemsAsList(this IPicker picker) => Enumerable.Range(0, picker.GetCount()).Select(i => picker.GetItem(i)).ToList();