Example #1
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);

            //if (e.Key != System.Windows.Input.Key.OemPeriod)
            //    return;
            if ((PartTextBox == null) || (PartTextBox.CaretIndex == 0))
            {
                return;
            }
            // Get the last word in the text (preceding the ".")
            string txt       = PartTextBox.Text;
            int    wordStart = txt.LastIndexOf(' ', PartTextBox.CaretIndex - 1);

            if (wordStart == -1)
            {
                wordStart = 0;
            }

            string lastWord = txt.Substring(wordStart, PartTextBox.CaretIndex - wordStart);



            // Check if the last word equal to the one we're waiting
            //if (lastWord.Trim().ToLower() != "item.")
            //    return;

            ShowPopup(PartTextBox.GetRectFromCharacterIndex(PartTextBox.CaretIndex, true));
        }
Example #2
0
        private void OnPartListKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            switch (e.Key)
            {
            case System.Windows.Input.Key.Enter:
                // Hide the Popup
                PartPopUp.IsOpen = false;

                ListBox lb = sender as ListBox;
                if (lb == null)
                {
                    return;
                }

                // Get the selected item value
                var country = lb.SelectedValue as Country;

                // Save the Caret position
                var textToInsert = $"{country.Name}-{country.Code}:Lat:{country.Latitude} , lon:{country.Longitude}";

                int i = PartTextBox.CaretIndex;
                // Add text to the text
                PartTextBox.Text = PartTextBox.Text.Insert(i, textToInsert);

                // Move the caret to the end of the added text
                PartTextBox.CaretIndex = i + textToInsert.Length;

                // Move focus back to the text box.
                // This will auto-hide the PopUp due to StaysOpen="false"
                PartTextBox.Focus();
                break;

            case System.Windows.Input.Key.Escape:
                // Hide the Popup
                PartPopUp.IsOpen = false;
                break;
            }
        }