示例#1
0
        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);
        }
示例#2
0
        /// <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());
            }
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
        /// <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;
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        /// <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("");
            }
        }
示例#7
0
        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);
        }
示例#8
0
        /// <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));
        }
示例#9
0
        /// <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);
        }
示例#10
0
        /// <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);
        }
示例#11
0
        /// <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);
            }
        }