public void AddItemToList(object input) { RegexOptions options = RegexOptions.None; Regex regex = new Regex("[ ]{2,}", options); // 1. Make sure the item is not blank if (Item == null || String.IsNullOrWhiteSpace(Item)) { return; } // 2. Format the item Item = Item.Trim(); Item = regex.Replace(Item, " "); // 3. Make sure the Listbox doesn't already contain the item if (ItemsSource.Contains(Item)) { return; } // 4. Add item to collection ItemsSource.Add(Item); // 5. Reset the item Item = null; }
private void DisplayInControl() { if (ItemsSource.Count > 0 && nodeList.All(node => node.Title != "All")) { nodeList.Add(new Node("All", "")); } // remove obsolete nodes foreach (var node in nodeList .Where(node => !ItemsSource.Contains(node.Title.Replace("__", "_")) && node.Title != "All").ToArray()) { nodeList.Remove(node); } // add new nodes and review the values foreach (var item in ItemsSource .Except(nodeList.Select(node => node.Title.Replace("__", "_")))) { var node = new Node(item.Replace("_", "__"), (FirstNotNullOrEmpty( ItemsAppendText ?? new Dictionary <string, string>(), item) ?? "").Replace("_", "__")); nodeList.Add(node); } }
async void Handle_UnFocused(object sender, Xamarin.Forms.FocusEventArgs e) { if (ItemsSource.Contains(TextBox.Text) == false) { TextBox.Text = ""; } await Frame.FadeTo(0, 200, Easing.SinOut); Frame.IsVisible = false; }
public void ReplaceTag(string oldValue, string newValue) { if (ItemsSource.Contains(oldValue)) { ItemsSource[ItemsSource.IndexOf(oldValue)] = newValue; } else { ItemsSource.Add(newValue); } }
private void OnCurrentChanged(object sender, EventArgs e) { var newValue = ItemsSource.CurrentItem as AcItemWrapper; if (ItemsSource.Contains(_selectedWrapper.Value)) { _selectedWrapper.Value = newValue; } else { _selectedWrapper.ForceValue(newValue); } }
public void Add(T item) { if (_readonly) { return; } if ((!_allowDuplicates && !ItemsSource.Contains(item)) && item != null && !item.Equals(_dummyItem)) { ItemsSource.Add(item); NextFrameActions.Enqueue(() => {}); } }
private void HideAndSelectFirst() { isShowing = false; lb.Visibility = Visibility.Collapsed; if (String.IsNullOrWhiteSpace(tb.Text) || ItemsSource == null || ItemsSource.Count == 0) { return; } if (!ItemsSource.Contains(tb.Text, new Compare())) { var sel = (from d in ItemsSource where d.ToLower().StartsWith(tb.Text.ToLower()) select d); Text = sel.FirstOrDefault() ?? String.Empty; } else { Text = tb.Text; OnItemChosen(); } }
private void HideAndSelectFirst() { isShowing = false; lb.Visibility = Visibility.Collapsed; if (String.IsNullOrWhiteSpace(tb.Text) || ItemsSource == null || ItemsSource.Count == 0) { return; } if (!ItemsSource.Contains(tb.Text, new Compare())) { var sel = (from d in ItemsSource where SearchFunction(d, this.tb.Text) select d); Text = sel.FirstOrDefault() ?? tb.Text; } else { Text = tb.Text; OnItemChosen(); } }
/// <summary> /// Check, if item exist in collection /// </summary> /// <param name="x">Check item</param> /// <returns>True, if not exist</returns> protected virtual bool GetDiff(T x) { return(!ItemsSource.Contains(x)); }