private HistoryService.HistoryItem?_GetSelectorItemUnderPoint(Point point)
        {
            HitTestResult hitTestResult = VisualTreeHelper.HitTest(_Selector, point);

            DependencyObject element = hitTestResult.VisualHit;

            while (element != null)
            {
                if (element.Equals(_Selector))
                {
                    return(null);
                }

                object item = _Selector.ItemContainerGenerator.ItemFromContainer(element);
                if (!item.Equals(DependencyProperty.UnsetValue))
                {
                    HistoryService.HistoryItem historyItem = (HistoryService.HistoryItem)item;
                    return(historyItem);
                }

                element = (DependencyObject)VisualTreeHelper.GetParent(element);
            }

            return(null);
        }
Esempio n. 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Debug.Assert(value is HistoryService.HistoryItem);
            Debug.Assert(targetType.Equals(typeof(ICollection <Inline>)));
            Debug.Assert(value != null);

            HistoryService.HistoryItem item = (HistoryService.HistoryItem)value;

            List <Inline> inlines = new List <Inline>();

            int startIndex = 0;
            int nextIndex  = 0;

            do
            {
                nextIndex = item.String.IndexOf(item.Substring, startIndex, StringComparison.InvariantCultureIgnoreCase);

                if (nextIndex == -1) // add remaining ordinary text
                {
                    inlines.Add(new Run(item.String.Substring(startIndex)));
                }
                else
                {
                    if (nextIndex != startIndex) // add ordinal text
                    {
                        inlines.Add(new Run(item.String.Substring(startIndex, nextIndex - startIndex)));
                    }

                    inlines.Add(new Bold(new Underline(new Run(item.String.Substring(nextIndex, item.Substring.Length)))));

                    startIndex = nextIndex + item.Substring.Length;
                }
            }while (nextIndex != -1);

            return(inlines);
        }
 private void _SetHistoryItemToTextBox(HistoryService.HistoryItem historyItem)
 {
     _TextBox.Text       = ((HistoryService.HistoryItem)historyItem).String;
     _TextBox.CaretIndex = _TextBox.Text.Length;
 }