/*+---------------------------------------------------------------------+
         |                                                                     |
         |                   TextBox Event Handling                            |
         |                                                                     |
         +---------------------------------------------------------------------*/

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (_textChangedByCode || Disabled || _dataProvider == null)
            {
                return;
            }
            var text = TextBox.Text;

            if (string.IsNullOrEmpty(text))
            {
                _popup.IsOpen = false;
                return;
            }
            if (_asynchronous)
            {
                if (_asyncThread != null && _asyncThread.IsAlive)
                {
                    _asyncThread.Interrupt();
                }
                _asyncThread = new Thread(() =>
                {
                    try
                    {
                        if (AsyncDelay > 0)
                        {
                            Thread.Sleep(AsyncDelay);
                        }
                        var dispatcher     = Application.Current.Dispatcher;
                        string currentText = dispatcher.Invoke(new Func <string>(() => TextBox.Text)).ToString();
                        if (text != currentText)
                        {
                            return;
                        }
                        var items   = _dataProvider.GetItems(text);
                        currentText = dispatcher.Invoke(new Func <string>(() => TextBox.Text)).ToString();
                        if (text != currentText)
                        {
                            return;
                        }
                        dispatcher.Invoke(new Action(() => PopulatePopupList(items)));
                    }
                    catch (ThreadInterruptedException tie)
                    {
                        Debug.Print("Interrupted");
                    }
                })
                {
                    IsBackground = true
                };
                _asyncThread.Start();
            }
            else
            {
                var items = _dataProvider.GetItems(text);
                PopulatePopupList(items);
            }
        }
Ejemplo n.º 2
0
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (_textChangedByCode || Disabled || _dataProvider == null)
            {
                return;
            }

            if (popupDelay == null)
            {
                popupDelay = new Timer(_ =>
                {
                    var dispatcher = Application.Current.Dispatcher;
                    string text    = (string)dispatcher.Invoke(new Func <string>(() => GetWordUnderCursor()));
                    if (String.IsNullOrEmpty(text))
                    {
                        dispatcher.Invoke((Action)(() => _popup.IsOpen = false));
                    }
                    else
                    {
                        var items = _dataProvider.GetItems(text).ToList();
                        dispatcher.Invoke((Action)(() => PopulatePopupList(items)));
                    }
                }, null, 100, Timeout.Infinite);
            }
            else
            {
                popupDelay.Change(100, Timeout.Infinite);
            }
        }
Ejemplo n.º 3
0
 private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (callFunction == 1)
     {
         if (_textChangedByCode || Disabled || _dataProvider == null)
         {
             return;
         }
         var text = _textBox.Text;
         if (string.IsNullOrEmpty(text))
         {
             _popup.IsOpen = false;
             return;
         }
         if (_asynchronous)
         {
             if (_asyncThread != null && _asyncThread.IsAlive)
             {
                 _asyncThread.Abort();
             }
             _asyncThread = new Thread(() =>
             {
                 List <string> theSaurisItems = new List <string>();
                 var items       = _dataProvider.GetItems(text, out theSaurisItems);
                 var dispatcher  = Application.Current.Dispatcher;
                 var currentText = dispatcher.Invoke(new Func <string>(() => _textBox.Text)).ToString();
                 if (text != currentText)
                 {
                     return;
                 }
                 dispatcher.Invoke(new Action(() => PopulatePopupList(items, theSaurisItems)));
             });
             _asyncThread.Start();
         }
         else
         {
             List <string> theSaurisItems = new List <string>();
             var           items          = _dataProvider.GetItems(text, out theSaurisItems);
             PopulatePopupList(items, theSaurisItems);
         }
     }
 }