Ejemplo n.º 1
0
        private static void OnItemFilterPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AutoCompleteBox source = (AutoCompleteBox)d;
            AutoCompleteFilterPredicate <object> value = (AutoCompleteFilterPredicate <object>)e.NewValue;

            if (value == null)
            {
                source.FilterMode = AutoCompleteFilterMode.None;
            }
            else
            {
                source.FilterMode = AutoCompleteFilterMode.Custom;
            }
        }
Ejemplo n.º 2
0
        public void Item_Search()
        {
            RunTest((control, textbox) =>
            {
                control.FilterMode = AutoCompleteFilterMode.Custom;
                control.ItemFilter = (search, item) =>
                {
                    string s = item as string;
                    return(s == null ? false : true);
                };

                // Just set to null briefly to exercise that code path
                AutoCompleteFilterPredicate <object> filter = control.ItemFilter;
                Assert.NotNull(filter);
                control.ItemFilter = null;
                Assert.Null(control.ItemFilter);
                control.ItemFilter = filter;
                Assert.NotNull(control.ItemFilter);

                textbox.Text = "a";
                Dispatcher.UIThread.RunJobs();
                Assert.Equal(textbox.Text, control.Text);

                textbox.Text = "acc";
                Dispatcher.UIThread.RunJobs();
                Assert.Equal(textbox.Text, control.Text);

                textbox.Text = "a";
                Dispatcher.UIThread.RunJobs();
                Assert.Equal(textbox.Text, control.Text);

                textbox.Text = "";
                Dispatcher.UIThread.RunJobs();
                Assert.Equal(textbox.Text, control.Text);

                textbox.Text = "cook";
                Dispatcher.UIThread.RunJobs();
                Assert.Equal(textbox.Text, control.Text);

                textbox.Text = "accept";
                Dispatcher.UIThread.RunJobs();
                Assert.Equal(textbox.Text, control.Text);

                textbox.Text = "cook";
                Dispatcher.UIThread.RunJobs();
                Assert.Equal(textbox.Text, control.Text);
            });
        }
Ejemplo n.º 3
0
        public TransactionViewModel(IEventAggregator eventAggregator)
        {
            eventAggregator.Subscribe(this);

            categoryFilter = (search, item) =>
            {
                if (string.IsNullOrEmpty(search))
                {
                    return(true);
                }

                if (item is CategoryDTO)
                {
                    string searchToLower = search.ToLower(CultureInfo.InvariantCulture);
                    return((item as CategoryDTO).Name.ToLower(CultureInfo.InvariantCulture).Contains(searchToLower));
                }

                return(false);
            };
            Translator.CultureChanged += (sender, args) => OperationDate = DateTime.Now;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to look through the view and locate the specific exact 
        /// text match.
        /// </summary>
        /// <param name="searchText">The search text.</param>
        /// <param name="view">The view reference.</param>
        /// <param name="predicate">The predicate to use for the partial or 
        /// exact match.</param>
        /// <returns>Returns the object or null.</returns>
        private object TryGetMatch(string searchText, ObservableCollection<object> view, AutoCompleteFilterPredicate<string> predicate)
        {
            if (view != null && view.Count > 0)
            {
                foreach (object o in view)
                {
                    if (predicate(searchText, FormatValue(o)))
                    {
                        return o;
                    }
                }
            }

            return null;
        }
Ejemplo n.º 5
0
        private void SelectFilter(AutoCompleteFilterMode mode)
        {
            switch (mode)
            {
            case AutoCompleteFilterMode.None:
                this._filterMode = AutoCompleteFilterMode.None;
                this._filter     = None;
                break;

            case AutoCompleteFilterMode.StartsWith:
                this._filterMode = AutoCompleteFilterMode.StartsWith;
                this._filter     = StartsWith;
                break;

            case AutoCompleteFilterMode.StartsWithCaseSensitive:
                this._filterMode = AutoCompleteFilterMode.StartsWithCaseSensitive;
                this._filter     = StartsWithCaseSensitive;
                break;

            case AutoCompleteFilterMode.StartsWithOrdinal:
                this._filterMode = AutoCompleteFilterMode.StartsWithOrdinal;
                this._filter     = StartsWithOrdinal;
                break;

            case AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive:
                this._filterMode = AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive;
                this._filter     = StartsWithOrdinalCaseSensitive;
                break;

            case AutoCompleteFilterMode.Contains:
                this._filterMode = AutoCompleteFilterMode.Contains;
                this._filter     = Contains;
                break;

            case AutoCompleteFilterMode.ContainsCaseSensitive:
                this._filterMode = AutoCompleteFilterMode.ContainsCaseSensitive;
                this._filter     = ContainsCaseSensitive;
                break;

            case AutoCompleteFilterMode.ContainsOrdinal:
                this._filterMode = AutoCompleteFilterMode.ContainsOrdinal;
                this._filter     = ContainsOrdinal;
                break;

            case AutoCompleteFilterMode.ContainsOrdinalCaseSensitive:
                this._filterMode = AutoCompleteFilterMode.ContainsOrdinalCaseSensitive;
                this._filter     = ContainsOrdinalCaseSensitive;
                break;

            case AutoCompleteFilterMode.Equals:
                this._filterMode = AutoCompleteFilterMode.Equals;
                this._filter     = Equals;
                break;

            case AutoCompleteFilterMode.EqualsCaseSensitive:
                this._filterMode = AutoCompleteFilterMode.EqualsCaseSensitive;
                this._filter     = EqualsCaseSensitive;
                break;

            case AutoCompleteFilterMode.EqualsOrdinal:
                this._filterMode = AutoCompleteFilterMode.EqualsOrdinal;
                this._filter     = EqualsOrdinal;
                break;

            case AutoCompleteFilterMode.EqualsOrdinalCaseSensitive:
                this._filterMode = AutoCompleteFilterMode.EqualsOrdinalCaseSensitive;
                this._filter     = EqualsOrdinalCaseSensitive;
                break;

            case AutoCompleteFilterMode.Custom:
                this._filterMode = AutoCompleteFilterMode.Custom;
                this._filter     = Custom;
                break;

            default:
                throw new ArgumentException("Filters can't be combined.");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Attempts to look through the view and locate the specific exact 
        /// text match.
        /// </summary>
        /// <param name="searchText">The search text.</param>
        /// <param name="view">The view reference.</param>
        /// <param name="predicate">The predicate to use for the partial or 
        /// exact match.</param>
        /// <returns>Returns the object or null.</returns>
        private object TryGetMatch(string searchText, ObservableCollection<object> view, AutoCompleteFilterPredicate<string> predicate)
        {
            if(view != null && view.Count > 0)
            {
                return view.FirstOrDefault(o => predicate(searchText, FormatValue(o)));
            }

            return null;
        }