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> /// Index function that retrieves the filter for the provided /// AutoCompleteSearchMode. /// </summary> /// <param name="searchMode">The built-in search mode.</param> /// <returns>Returns the string-based comparison function.</returns> public static AutoCompleteSearchPredicate<string> GetFilter(AutoCompleteSearchMode searchMode) { switch (searchMode) { case AutoCompleteSearchMode.Contains: return Contains; case AutoCompleteSearchMode.ContainsCaseSensitive: return ContainsCaseSensitive; case AutoCompleteSearchMode.ContainsOrdinal: return ContainsOrdinal; case AutoCompleteSearchMode.ContainsOrdinalCaseSensitive: return ContainsOrdinalCaseSensitive; case AutoCompleteSearchMode.Equals: return Equals; case AutoCompleteSearchMode.EqualsCaseSensitive: return EqualsCaseSensitive; case AutoCompleteSearchMode.EqualsOrdinal: return EqualsOrdinal; case AutoCompleteSearchMode.EqualsOrdinalCaseSensitive: return EqualsOrdinalCaseSensitive; case AutoCompleteSearchMode.StartsWith: return StartsWith; case AutoCompleteSearchMode.StartsWithCaseSensitive: return StartsWithCaseSensitive; case AutoCompleteSearchMode.StartsWithOrdinal: return StartsWithOrdinal; case AutoCompleteSearchMode.StartsWithOrdinalCaseSensitive: return StartsWithOrdinalCaseSensitive; case AutoCompleteSearchMode.None: case AutoCompleteSearchMode.Custom: default: return null; } }
/// <summary> /// Index function that retrieves the filter for the provided /// AutoCompleteSearchMode. /// </summary> /// <param name="searchMode">The built-in search mode.</param> /// <returns>Returns the string-based comparison function.</returns> public static AutoCompleteSearchPredicate <string> GetFilter(AutoCompleteSearchMode searchMode) { switch (searchMode) { case AutoCompleteSearchMode.Contains: return(Contains); case AutoCompleteSearchMode.ContainsCaseSensitive: return(ContainsCaseSensitive); case AutoCompleteSearchMode.ContainsOrdinal: return(ContainsOrdinal); case AutoCompleteSearchMode.ContainsOrdinalCaseSensitive: return(ContainsOrdinalCaseSensitive); case AutoCompleteSearchMode.Equals: return(Equals); case AutoCompleteSearchMode.EqualsCaseSensitive: return(EqualsCaseSensitive); case AutoCompleteSearchMode.EqualsOrdinal: return(EqualsOrdinal); case AutoCompleteSearchMode.EqualsOrdinalCaseSensitive: return(EqualsOrdinalCaseSensitive); case AutoCompleteSearchMode.StartsWith: return(StartsWith); case AutoCompleteSearchMode.StartsWithCaseSensitive: return(StartsWithCaseSensitive); case AutoCompleteSearchMode.StartsWithOrdinal: return(StartsWithOrdinal); case AutoCompleteSearchMode.StartsWithOrdinalCaseSensitive: return(StartsWithOrdinalCaseSensitive); case AutoCompleteSearchMode.None: case AutoCompleteSearchMode.Custom: default: return(null); } }