Exemplo n.º 1
0
        private void AddAutoSuggestMultipleItem(ObservableCollection <BindableDynamicDictionary> items)
        {
            var    item      = new BindableDynamicDictionary();
            string fieldName = AutoSuggestMultipleFieldName();

            item[AutoSuggestMultipleTextPath(fieldName)] = "";
            item[AutoSuggestSourceName(fieldName)]       = new ObservableCollection <string>();
            item[BusyBindModelName(fieldName)]           = false; // populating the item source or not...

            items.Add(item);
        }
Exemplo n.º 2
0
        private void SetupTimerForAutoComplete(BindableDynamicDictionary model,
                                               string fieldName,
                                               AutoCompleteBox tb,
                                               Func <string, IEnumerable <string> > itemsGenerator)
        {
            string timerName = TimerName(fieldName);
            var    timer     = new System.Windows.Threading.DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(600)
            };

            timer.Tick += (sender, args) =>
            {
                timer.Stop(); // stop the timer, so that it can be started again the next time someone types
                PopulateAutoComplete(tb, itemsGenerator, model, fieldName);
            };

            model[timerName] = timer; // may need to save this...
        }
Exemplo n.º 3
0
        private void PopulateAutoComplete(AutoCompleteBox tb,
                                          Func <string, IEnumerable <string> > itemsGenerator,
                                          BindableDynamicDictionary model,
                                          string itemFieldName)
        {
            var    source   = model[AutoSuggestSourceName(itemFieldName)] as ObservableCollection <string>;
            string busyName = BusyBindModelName(itemFieldName);

            model[busyName] = true;

            string textBoxTextCopy = tb.Text;

            Thread t = new Thread(() =>
            {
                try
                {
                    var items = itemsGenerator(textBoxTextCopy);

                    tb.Dispatcher.Invoke(() =>
                    {
                        source.Clear();
                        foreach (string i in items)
                        {
                            source.Add(i);
                        }
                    });
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    tb.Dispatcher.Invoke(() =>
                    {
                        model[busyName] = false;
                    });
                }
            });

            t.Start();
        }