private static void OnSearchModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; AutoCompleteSearchMode mode = (AutoCompleteSearchMode)e.NewValue; if (mode != AutoCompleteSearchMode.Contains && mode != AutoCompleteSearchMode.ContainsCaseSensitive && mode != AutoCompleteSearchMode.ContainsOrdinal && mode != AutoCompleteSearchMode.ContainsOrdinalCaseSensitive && mode != AutoCompleteSearchMode.Custom && mode != AutoCompleteSearchMode.Equals && mode != AutoCompleteSearchMode.EqualsCaseSensitive && mode != AutoCompleteSearchMode.EqualsOrdinal && mode != AutoCompleteSearchMode.EqualsOrdinalCaseSensitive && mode != AutoCompleteSearchMode.None && mode != AutoCompleteSearchMode.StartsWith && mode != AutoCompleteSearchMode.StartsWithCaseSensitive && mode != AutoCompleteSearchMode.StartsWithOrdinal && mode != AutoCompleteSearchMode.StartsWithOrdinalCaseSensitive) { source.SetValue(e.Property, e.OldValue); throw new ArgumentException("", "value"); } // Sets the filter predicate for the new value AutoCompleteSearchMode newValue = (AutoCompleteSearchMode)e.NewValue; source.TextFilter = AutoCompleteSearch.GetFilter(newValue); }
/// <summary> /// ConverterCultureProperty property changed handler. /// </summary> /// <param name="d"> /// AutoCompleteBox that changed its ConverterCulture. /// </param> /// <param name="e">Event arguments.</param> private static void OnConverterCulturePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; if (source.View != null && source.View.Count > 0) { source.ToggleDropDown(d, new RoutedEventArgs()); } }
/// <summary> /// MinimumPrefixLengthProperty property changed handler. /// </summary> /// <param name="d">AutoCompleteBox that changed its MinimumPrefixLength.</param> /// <param name="e">Event arguments.</param> private static void OnMinimumPrefixLengthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; int newValue = (int)e.NewValue; // If negative, coerce the value to -1 if (newValue < 0 && newValue != -1) { source.SetValue(e.Property, -1); } }
/// <summary> /// ItemFilterProperty property changed handler. /// </summary> /// <param name="d">AutoCompleteBox that changed its ItemFilter.</param> /// <param name="e">Event arguments.</param> private static void OnItemFilterPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; Func <string, object, bool> value = e.NewValue as Func <string, object, bool>; // If null, revert to the "None" predicate if (value == null) { source.SearchMode = AutoCompleteSearchMode.None; } else { source.SearchMode = AutoCompleteSearchMode.Custom; source.TextFilter = null; } }
private static void OnMinimumPopulateDelayPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; if (source.IgnorePropertyChange) { source.IgnorePropertyChange = false; return; } int newValue = (int)e.NewValue; if (newValue < 0) { source.IgnorePropertyChange = true; d.SetValue(e.Property, e.OldValue); throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}", newValue), "value"); } // Stop any existing timer if (source.DelayTimer != null) { source.DelayTimer.Stop(); if (newValue == 0) { source.DelayTimer = null; } } // Create or clear a dispatcher timer instance if (newValue > 0 && source.DelayTimer == null) { source.DelayTimer = new DispatcherTimer(); source.DelayTimer.Tick += source.PopulateDropDown; } // Set the new tick interval if (newValue > 0 && source.DelayTimer != null) { source.DelayTimer.Interval = TimeSpan.FromMilliseconds(newValue); } }
/// <summary> /// OnSearchTextProperty property changed handler. /// </summary> /// <param name="d">AutoCompleteBox that changed its SearchText.</param> /// <param name="e">Event arguments.</param> private static void OnSearchTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; if (source.IgnorePropertyChange) { source.IgnorePropertyChange = false; return; } // Ensure the property is only written when expected if (!source.AllowWrite) { // Reset the old value before it was incorrectly written source.IgnorePropertyChange = true; source.SetValue(e.Property, e.OldValue); throw new InvalidOperationException(""); } }
private static void OnMaxDropDownHeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; if (source.IgnorePropertyChange) { source.IgnorePropertyChange = false; return; } double newValue = (double)e.NewValue; // Revert to the old value if invalid (negative) if (newValue < 0) { source.IgnorePropertyChange = true; source.SetValue(e.Property, e.OldValue); throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}", e.NewValue), "value"); } source.OnMaxDropDownHeightChanged(newValue); }
/// <summary> /// SelectedItemProperty property changed handler. Fires the /// SelectionChanged event. The event data will contain any non-null /// removed items and non-null additions. /// </summary> /// <param name="d">AutoCompleteBox that changed its SelectedItem.</param> /// <param name="e">Event arguments.</param> private static void OnSelectedItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; if (source.IgnorePropertyChange) { source.IgnorePropertyChange = false; return; } // Ensure the property is only written when expected if (!source.AllowWrite) { // Reset the old value before it was incorrectly written source.IgnorePropertyChange = true; source.SetValue(e.Property, e.OldValue); throw new InvalidOperationException(""); } List <object> removed = new List <object>(); if (e.OldValue != null) { removed.Add(e.OldValue); } List <object> added = new List <object>(); if (e.NewValue != null) { added.Add(e.NewValue); } // source.OnSelectionChanged(new SelectionChangedEventArgs(null,removed, added)); }
/// <summary> /// TextProperty property changed handler. /// </summary> /// <param name="d">AutoCompleteBox that changed its Text.</param> /// <param name="e">Event arguments.</param> private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; source.TextUpdated((string)e.NewValue, false); }
/// <summary> /// ItemsSourceProperty property changed handler. /// </summary> /// <param name="d">AutoCompleteBox that changed its ItemsSource.</param> /// <param name="e">Event arguments.</param> private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox autoComplete = d as AutoCompleteTextBox; autoComplete.OnItemsSourceChanged((IEnumerable)e.OldValue, (IEnumerable)e.NewValue); }
/// <summary> /// IsDropDownOpenProperty property changed handler. /// </summary> /// <param name="d">AutoCompleteTextBox that changed its IsDropDownOpen.</param> /// <param name="e">Event arguments.</param> private static void OnIsDropDownOpenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox source = d as AutoCompleteTextBox; // Ignore the change if requested if (source.IgnorePropertyChange) { source.IgnorePropertyChange = false; return; } bool oldValue = (bool)e.OldValue; bool newValue = (bool)e.NewValue; bool delayedClosingVisual = source.PopupClosedVisualState; RoutedPropertyChangingEventArgs <bool> args = new RoutedPropertyChangingEventArgs <bool>(e.Property, oldValue, newValue, true); AutoCompleteBoxAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(source) as AutoCompleteBoxAutomationPeer; if (peer != null) { peer.RaiseExpandCollapseAutomationEvent(oldValue, newValue); } if (newValue) { // Opening source.OnDropDownOpening(args); // Opened if (!args.Cancel) { source.OpenDropDown(oldValue, newValue); } } else { // Closing source.OnDropDownClosing(args); if (source.View == null || source.View.Count == 0) { delayedClosingVisual = false; } // Immediately close the drop down window: // When a popup closed visual state is present, the code path is // slightly different and the actual call to CloseDropDown will // be called only after the visual state's transition is done if (!args.Cancel && !delayedClosingVisual) { source.CloseDropDown(oldValue, newValue); } } // If canceled, revert the value change if (args.Cancel) { source.IgnorePropertyChange = true; source.SetValue(e.Property, oldValue); } // Closing call when visual states are in use if (delayedClosingVisual) { source.UpdateVisualState(true); } }