/// <summary> /// Create a picker with the optional title and selectedIndexChange event method. /// </summary> /// <param name="titleLabel">Title on top of the list items.</param> /// <param name="selectedIndexChangeDelegate">Method to call when the event SelectedItemChanged is triggered on the picker control.</param> /// <param name="itemsSource">Items to show in the picker.</param> /// <param name="startIndex">Index of the initially selected item.</param> /// <returns>A new instance of PickerEx control.</returns> public static PickerEx CreatePicker(string titleLabel, SelectItemAction selectedIndexChangeDelegate, IEnumerable itemsSource, int startIndex) { string title = titleLabel == null ? null : titleLabel; PickerEx picker = new PickerEx(); if (!String.IsNullOrEmpty(title)) { picker.Title = title; } picker.ItemsSource = itemsSource; // Set the initial index before adding a handler. picker.SelectedIndex = startIndex; if (selectedIndexChangeDelegate != null) { int previousIndex = picker.SelectedIndex; picker.SelectedIndexChanged += async(sender, args) => { if (picker.SelectedIndex > -1 && picker.SelectedIndex != previousIndex) { string key = picker.Items[picker.SelectedIndex]; if (await selectedIndexChangeDelegate(key, picker.SelectedIndex)) { previousIndex = picker.SelectedIndex; } else { // Set back to previous index picker.SelectedIndex = previousIndex; } } }; } return(picker); }
private void SelectItem(SelectItemAction pSelectItemAction) { ArgumentsValidation.NotNull(pSelectItemAction, "pSelectItemAction"); var item = pSelectItemAction.SelectedItem as ChapterInformation; if (item == null) { throw new InvalidOperationException("Cannot selected an item that is not a chapter"); } if (!_chapters.Contains(item)) { throw new InvalidOperationException("Cannot select an item that is not in list"); } SelectChapter(item); }
/// <summary> /// Create a picker with the optional title and selectedIndexChange event method. /// </summary> /// <param name="titleLabel">Title on top of the list items.</param> /// <param name="selectedIndexChangeDelegate">Method to call when the event SelectedItemChanged is triggered on the picker control.</param> /// <returns>A new instance of PickerEx control.</returns> public static PickerEx CreatePicker(string titleLabel = null, SelectItemAction selectedIndexChangeDelegate = null) { return(ControlFactory.CreatePicker(titleLabel, selectedIndexChangeDelegate, null, 0)); }