예제 #1
0
        /// <summary>
        /// Search Event was triggerd
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchTextBox_Search(object sender, RoutedEventArgs e)
        {
            // First of all reload the Textbox in case we gote some Style we do not want
            UpdateViewStateDependence(settings.viewSettings);

            // Get the Sender as a Search Box
            UIControls.SearchTextBox searchBox = (UIControls.SearchTextBox)sender;

            string mySearchString = searchBox.Text;

            TextRange range = new TextRange(rtbInOutData.Document.ContentStart, rtbInOutData.Document.ContentEnd);
            //range.Text = @"TOP a multiline text or file END";
            Regex reg = new Regex("(" + mySearchString + ")", RegexOptions.Compiled | RegexOptions.IgnoreCase);

            var start = rtbInOutData.Document.ContentStart;

            while (start != null && start.CompareTo(rtbInOutData.Document.ContentEnd) < 0)
            {
                if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
                {
                    var match = reg.Match(start.GetTextInRun(LogicalDirection.Forward));

                    var textrange = new TextRange(start.GetPositionAtOffset(match.Index, LogicalDirection.Forward), start.GetPositionAtOffset(match.Index + match.Length, LogicalDirection.Backward));
                    textrange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Yellow));
                    textrange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                    start = textrange.End; // I'm not sure if this is correct or skips ahead too far, try it out!!!
                }
                start = start.GetNextContextPosition(LogicalDirection.Forward);
            }
        }
 public void InitSecondSearchBox(ref UIControls.SearchTextBox serchTextBox)
 {
     SearchTextBoxControl = new SearchTextBoxControl()
     {
         This = serchTextBox,
     };
     SearchTextBoxControl.SetUserIcon("pack://application:,,,/SearchTextBox;component/Images/user.png");
     SearchTextBoxControl.SetGrupCopyIcon("pack://application:,,,/SearchTextBox;component/Images/Group copy.png");
     SearchTextBoxControl.SetSelectionStyle(UIControls.SearchTextBox.SectionsStyles.CheckBoxStyle);
     SearchTextBoxControl.CreateSelections();  //Changing
 }