/// <summary> /// (Internal) Called whenever an input event is raised when this control is displayed. /// </summary> /// <param name="key">The key or gamepad button that raised the event</param> /// <param name="modifiers">Which modifier keys are down?</param> /// <param name="gamepadIndex">Index of the gamepad that raised the event, if the key is a gamepad button, or -1 if it was a keyboard key</param> /// <param name="isRepeat">Is this a "repeated key press" event, automatically generated while the used holds the key down?</param> internal override void OnInputEvent(KeyCode key, ModifierKeys modifiers, int gamepadIndex, bool isRepeat) { if (!Enabled || (MenuItems.Count == 0)) { return; // Not enabled or no menu items, do nothing } if (SelectionUpKeys.Contains(key)) { //SelectedIndex_--; //if (SelectedIndex_ < 0) SelectedIndex_ = LoopItemSelection ? MenuItems.Count - 1 : 0; SelectedIndex_ = GetNextNonSeparatorIndex(SelectedIndex - 1, -1); if (MenuItems[SelectedIndex_].HasValue) { OnSelectedItemChanged?.Invoke(SelectedIndex, MenuItems[SelectedIndex_].Value.Key, MenuItems[SelectedIndex_].Value.Text); } Page.UI.Invalidate(); } else if (SelectionDownKeys.Contains(key)) { //SelectedIndex_++; //if (SelectedIndex_ >= MenuItems.Count) SelectedIndex_ = LoopItemSelection? 0 : MenuItems.Count - 1; SelectedIndex_ = GetNextNonSeparatorIndex(SelectedIndex + 1, 1); if (MenuItems[SelectedIndex_].HasValue) { OnSelectedItemChanged?.Invoke(SelectedIndex, MenuItems[SelectedIndex_].Value.Key, MenuItems[SelectedIndex_].Value.Text); } Page.UI.Invalidate(); } else if (ValidationKeys.Contains(key)) { ValidateSelection(); } }
private void UpdateSelectedItem(object value) { _selectedItem = value; CellBase cell = _list.Children.OfType <CellBase>().FirstOrDefault(c => c.Item == value); MarkCellAsSelected(cell); OnSelectedItemChanged?.Invoke(this, new SelectedItemEventArgs(_selectedItem)); }
/// <summary> /// 下拉框选项点击时调用此方法 /// </summary> protected async Task OnItemClick(SelectedItem item) { item.Active = true; SelectedItem = item; CurrentValueAsString = item.Value; // 触发 SelectedItemChanged 事件 if (OnSelectedItemChanged != null) { await OnSelectedItemChanged.Invoke(SelectedItem); } }
/// <summary> /// /// </summary> /// <returns></returns> private async Task ItemChanged(SelectedItem item) { item.Active = true; SelectedItem = item; CurrentValueAsString = item.Value; // 触发 SelectedItemChanged 事件 if (OnSelectedItemChanged != null) { await OnSelectedItemChanged.Invoke(SelectedItem); } if (AutoClearSearchText) { SearchText = string.Empty; } }
/// <summary> /// OnAfterRenderAsync 方法 /// </summary> /// <param name="firstRender"></param> /// <returns></returns> protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); if (firstRender) { if (Interop == null) { Interop = new JSInterop <Select <TValue> >(JSRuntime); } await Interop.InvokeVoidAsync(this, SelectElement, "bb_select", nameof(ConfirmSelectedItem)); if (SelectedItem != null && OnSelectedItemChanged != null) { await OnSelectedItemChanged.Invoke(SelectedItem); } } }
/// <summary> /// Removes a menu item. CAUTION: Will mess up the menu item indices. /// </summary> /// <param name="index">Index of the menu item to remove</param> public void RemoveMenuItem(int index) { if ((index < 0) || (index >= MenuItems.Count)) { return; } MenuItems.RemoveAt(index); if (SelectedIndex_ >= MenuItems.Count) { SelectedIndex_ = MenuItems.Count - 1; if (MenuItems[SelectedIndex_].HasValue) { OnSelectedItemChanged?.Invoke(SelectedIndex, MenuItems[SelectedIndex_].Value.Key, MenuItems[SelectedIndex_].Value.Text); } } Page.UI.Invalidate(); }
/// <summary> /// 下拉框选项点击时调用此方法 /// </summary> private async Task OnItemClick(SelectedItem item) { if (!item.IsDisabled) { var i = Items.FirstOrDefault(i => i.Active); if (i != null) { i.Active = false; } item.Active = true; SelectedItem = item; CurrentValueAsString = item.Value; // 触发 SelectedItemChanged 事件 if (OnSelectedItemChanged != null) { await OnSelectedItemChanged.Invoke(SelectedItem); } } }
/// <summary> /// 下拉框选项点击时调用此方法 /// </summary> protected async Task OnItemClick(SelectedItem item) { if (!item.IsDisabled) { if (SelectedItem != null) { SelectedItem.Active = false; } SelectedItem = item; SelectedItem.Active = true; // ValueChanged CurrentValueAsString = SelectedItem.Value; // 触发 SelectedItemChanged 事件 if (OnSelectedItemChanged != null) { await OnSelectedItemChanged.Invoke(SelectedItem); } } }
/// <summary> /// OnAfterRenderAsync 方法 /// </summary> /// <param name="firstRender"></param> /// <returns></returns> protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); if (firstRender) { if (OnSearchTextChanged == null) { OnSearchTextChanged = text => Items.Where(i => i.Text.Contains(text, StringComparison.OrdinalIgnoreCase)); } if (Interop == null) { Interop = new JSInterop <Select <TValue> >(JSRuntime); } await Interop.Invoke(this, SelectElement, "bb_select", nameof(ConfirmSelectedItem)); if (Initialized && SelectedItem != null && OnSelectedItemChanged != null) { await OnSelectedItemChanged.Invoke(SelectedItem); } } }
/// <summary> /// 选择的实例有变更 /// <para>触发</para> /// </summary> /// <param name="selected_item"></param> protected virtual void RaiseSelectedItemChanged(T selected_item) { DHelper.InvokeOnMain(() => OnSelectedItemChanged?.Invoke(selected_item)); }