当前位置: 首页>>代码示例>>C#>>正文


C# TextRange.ClearAllProperties方法代码示例

本文整理汇总了C#中System.Windows.Documents.TextRange.ClearAllProperties方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.ClearAllProperties方法的具体用法?C# TextRange.ClearAllProperties怎么用?C# TextRange.ClearAllProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.TextRange的用法示例。


在下文中一共展示了TextRange.ClearAllProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Find

        public void Find(string _find)
        {
            TextRange documentRange = new TextRange(this.Document.ContentStart, this.Document.ContentEnd);
            documentRange.ClearAllProperties();
            _trs.Clear();
            TextPointer navigator = this.Document.ContentStart;
            while (navigator.CompareTo(this.Document.ContentEnd) < 0)
            {
                TextPointerContext context = navigator.GetPointerContext(LogicalDirection.Backward);
                if (context == TextPointerContext.ElementStart && navigator.Parent is Run)
                {
                    Run r = ((Run)navigator.Parent);
                    string text = r.Text;

                    Match m = Regex.Match(text, _find);
                    if (m.Success)
                    {
                        TextPointer tp = r.ElementStart;
                        TextRange range = new TextRange(tp.GetPositionAtOffset(m.Index + 1), tp.GetPositionAtOffset(m.Index + m.Length + 1));
                        _trs.Add(range);
                    }
                }
                navigator = navigator.GetNextContextPosition(LogicalDirection.Forward);
            }
            foreach (TextRange range in _trs)
                range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Yellow));
            FindNext();

        }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:29,代码来源:Controls.cs

示例2: Update

        private void Update()
        {
            var control = this.LogBox;
            if (control == null) return;

            var currentStart = control.Selection.Start;
            var currentEnd = control.Selection.End;
            control.SelectAll();
            var allRange = new TextRange(control.Selection.Start,control.Selection.End);
            var allText = control.Selection.Text;
            allRange.ClearAllProperties();

            foreach(var regexPair in ViewModel.RegexTextFormats)
            {
                var regex = new Regex(regexPair.Key);
                var resultList = regex.Matches(allText);

                foreach(Match result in resultList)
                {
                    var matchStartPoint = allRange.Start.GetPositionAtOffset(result.Index);
                    var matchEndPoint = matchStartPoint.GetPositionAtOffset(result.Length);
                    control.Selection.Select(matchStartPoint, matchEndPoint);
                    foreach (var props in regexPair.Value)
                    {
                        control.Selection.ApplyPropertyValue(props.textElementProperty, props.value);
                    }
                }
            }

            control.Selection.Select(currentStart, currentEnd);
        }
开发者ID:IrisTechnica,项目名称:Iris-Engine,代码行数:31,代码来源:LogController.xaml.cs

示例3: SetText

        public void SetText(string text)
        {
            TextRange range = new TextRange(sourceCodeRichTextBox.Document.ContentStart, sourceCodeRichTextBox.Document.ContentEnd);
            range.Text = text;

            if (sourceCodeRichTextBox.Document == null)
                return;

            TextRange documentRange = new TextRange(sourceCodeRichTextBox.Document.ContentStart, sourceCodeRichTextBox.Document.ContentEnd);
            documentRange.ClearAllProperties();

            TextPointer navigator = sourceCodeRichTextBox.Document.ContentStart;
            while (navigator.CompareTo(sourceCodeRichTextBox.Document.ContentEnd) < 0)
            {
                TextPointerContext context = navigator.GetPointerContext(LogicalDirection.Backward);
                if (context == TextPointerContext.ElementStart && navigator.Parent is Run)
                {
                    SyntaxHighlight v = new SyntaxHighlight();

                    v.ApplyColors((Run)navigator.Parent);

                }
                navigator = navigator.GetNextContextPosition(LogicalDirection.Forward);
            }
        }
开发者ID:jerry27syd,项目名称:WPFs,代码行数:25,代码来源:HightlightRichTextBoxControl.xaml.cs

示例4: ApplyFormatClick

        private void ApplyFormatClick(object sender, RoutedEventArgs e)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            FlowDocument doc = Rtb.Document;
            TextRange range = new TextRange(doc.ContentStart, doc.ContentEnd);
            range.ClearAllProperties();
            int i = 0;
            while (true)
            {
                TextPointer p1 = range.Start.GetPositionAtOffset(i);
                i++;
                TextPointer p2 = range.Start.GetPositionAtOffset(i);
                if (p2 == null)
                    break;
                TextRange tempRange = new TextRange(p1, p2);
                if (tempRange != null)
                {

                    tempRange.ApplyPropertyValue(TextElement.ForegroundProperty, _blueBrush);
                    tempRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                }
                i++;

            }
            Time.Text = "Formatting took: " + stopwatch.ElapsedMilliseconds + " ms, number of characters: " + range.Text.Length;
        }
开发者ID:JohanLarsson,项目名称:FlowDocDummy,代码行数:26,代码来源:MainWindow.xaml.cs

示例5: PasteContentData

 internal static bool PasteContentData(InputBox inputBox, IDataObject iDataObject)
 {
     TextData data = TryGetText(iDataObject);
     if (!data.ContainsData)
     {
         if (iDataObject.GetDataPresent(DataFormats.Bitmap, true))
         {
             inputBox.Paste(iDataObject);
             return true;
         }
         return false;
     }
     inputBox.TempFlowDocument.Blocks.Clear();
     TextRange range = null;
     if (data.Format == BamaDataFormat)
     {
         object obj2 = XamlReader.Parse(data.Data);
         if (obj2 is Block)
         {
             inputBox.TempFlowDocument.Blocks.Add(obj2 as Block);
         }
         else if (obj2 is Inline)
         {
             Span span = new Span(inputBox.TempFlowDocument.ContentStart, inputBox.TempFlowDocument.ContentEnd)
             {
                 Inlines = { obj2 as Span }
             };
         }
         range = new TextRange(inputBox.TempFlowDocument.ContentStart, inputBox.TempFlowDocument.ContentEnd);
         range.ClearAllProperties();
         inputBox.Selection.Text = "";
         Span newspan = new Span(inputBox.Selection.Start, inputBox.Selection.End);
         ReplaceControls.AddBlocksToSpan(inputBox.TempFlowDocument, newspan);
         inputBox.CaretPosition = newspan.ElementEnd.GetInsertionPosition(LogicalDirection.Forward);
     }
     else
     {
         range = new TextRange(inputBox.TempFlowDocument.ContentStart, inputBox.TempFlowDocument.ContentEnd);
         using (MemoryStream stream = new MemoryStream())
         {
             using (StreamWriter writer = new StreamWriter(stream))
             {
                 writer.Write(data.Data);
                 writer.Flush();
                 stream.Position = 0L;
                 range.Load(stream, data.Format);
             }
         }
         range.ClearAllProperties();
         inputBox.Selection.Text = "";
         Span span3 = new Span(inputBox.Selection.Start, inputBox.Selection.End);
         ReplaceControls.AddBlocksToSpan(inputBox.TempFlowDocument, span3);
         inputBox.CaretPosition = span3.ElementEnd.GetInsertionPosition(LogicalDirection.Forward);
     }
     inputBox.TempFlowDocument.Blocks.Clear();
     return true;
 }
开发者ID:QuocHuy7a10,项目名称:Arianrhod,代码行数:57,代码来源:ClipboardMgr.cs

示例6: FormatCurrentLine

        public void FormatCurrentLine()
        {
            /*These checks are necessary to invoke FormatCurrentLinefunction as it uses Caret related properties
            and is included in TextChange event handler. So, if you need to execute this function elsewhere, include these checks.
            
            if (rtb1.Document == null)
                return;
            if (rtb1.CaretPosition.Paragraph == null)
                return;
            if (rtb1.CaretPosition.Paragraph.Inlines.FirstInline == null)
                return;
            */

            int i;
            string s;
            Run r;

            TextRange paragraphRange = new TextRange(rtb1.CaretPosition.Paragraph.ContentStart, rtb1.CaretPosition.Paragraph.ContentEnd);
            paragraphRange.ClearAllProperties();

            r = (Run)(rtb1.CaretPosition.Paragraph.Inlines.FirstInline);
            if (r.Text == null)
                return;
            s = r.Text;

            registerMatches = register.Matches(s);
            digitMatches = digit.Matches(s);
            keywordMatches = keyword.Matches(s);
            commentMatches = comment.Matches(s);

            for (i = 0; i <= registerMatches.Count - 1; i++)
            {
                TextRange temp = new TextRange(r.ContentStart.GetPositionAtOffset(registerMatches[i].Index, LogicalDirection.Forward), r.ContentStart.GetPositionAtOffset(registerMatches[i].Index + registerMatches[i].Length, LogicalDirection.Forward));
                registerAllMatches.Add(temp);
            }

            for (i = 0; i <= digitMatches.Count - 1; i++)
            {
                TextRange temp = new TextRange(r.ContentStart.GetPositionAtOffset(digitMatches[i].Index, LogicalDirection.Forward), r.ContentStart.GetPositionAtOffset(digitMatches[i].Index + digitMatches[i].Length, LogicalDirection.Forward));
                digitAllMatches.Add(temp);
            }

            for (i = 0; i <= keywordMatches.Count - 1; i++)
            {
                TextRange temp = new TextRange(r.ContentStart.GetPositionAtOffset(keywordMatches[i].Index, LogicalDirection.Forward), r.ContentStart.GetPositionAtOffset(keywordMatches[i].Index + keywordMatches[i].Length, LogicalDirection.Forward));
                keywordAllMatches.Add(temp);
            }

            for (i = 0; i <= commentMatches.Count - 1; i++)
            {
                TextRange temp = new TextRange(r.ContentStart.GetPositionAtOffset(commentMatches[i].Groups["comment"].Index, LogicalDirection.Forward), r.ContentStart.GetPositionAtOffset(commentMatches[i].Groups["comment"].Index + commentMatches[i].Groups["comment"].Length, LogicalDirection.Forward));
                commentAllMatches.Add(temp);
            }

            Format();
        }
开发者ID:anujgeek,项目名称:Microprocessor8085Simulator,代码行数:56,代码来源:SyntaxHighlighting.cs

示例7: FormatOnFly

 public void FormatOnFly()
 {
     TextPointer pos = _editor.CaretPosition;
     TextPointer start = pos.GetLineStartPosition(0);
     TextPointer end = pos.GetLineStartPosition(1);
     end = (end ?? pos.DocumentEnd).GetInsertionPosition(LogicalDirection.Backward);
     TextRange range = new TextRange(start, end);
     range.ClearAllProperties();
     CheckWords(range.Text, start);
 }
开发者ID:MotorViper,项目名称:FormGenerator,代码行数:10,代码来源:RichTextBoxEditor.cs

示例8: ComboBoxFontColor_SelectionChanged

 private void ComboBoxFontColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!richMain.Selection.IsEmpty)
     {
         TextRange range = new TextRange(richMain.Selection.Start, richMain.Selection.End);
         if (ComboBoxFontColor.SelectedValue.ToString() != "None")
         {
             Brush b = (Brush)new BrushConverter().ConvertFromString(ComboBoxFontColor.SelectedValue.ToString());
             range.ApplyPropertyValue(RichTextBox.ForegroundProperty, b);
         }
         else
         {
             range.ClearAllProperties();
         }
     }
 }
开发者ID:wan-qy,项目名称:CenaPlus,代码行数:16,代码来源:Circulars.xaml.cs

示例9: HeadersTextChanged

        private void HeadersTextChanged(object sender, TextChangedEventArgs e)
        {
            if (Headers.Document == null) return;
            httpInterceptorViewModel.SetRequestHeaders(new TextRange(Headers.Document.ContentStart, Headers.Document.ContentEnd).Text);
            var documentRange = new TextRange(Headers.Document.ContentStart, Headers.Document.ContentEnd);
            documentRange.ClearAllProperties();

            TextPointer navigator = Headers.Document.ContentStart;
            while (navigator.CompareTo(Headers.Document.ContentEnd) < 0)
            {
                TextPointerContext context = navigator.GetPointerContext(LogicalDirection.Backward);
                if (context == TextPointerContext.ElementStart && navigator.Parent is Run)
                {
                    //CheckHeaderWordsInRun((Run)navigator.Parent);
                }
                navigator = navigator.GetNextContextPosition(LogicalDirection.Forward);
            }
            //FormatHeaders();
        }
开发者ID:seanmcalinden,项目名称:restbox,代码行数:19,代码来源:HttpInterceptor.xaml.cs

示例10: GenerateClipBoardData

 public static void GenerateClipBoardData(DataObjectCopyingEventArgs e, TextSelection selection)
 {
     string str;
     using (MemoryStream stream = new MemoryStream())
     {
         TextRange range = new TextRange(selection.Start, selection.End);
         range.ClearAllProperties();
         range.Save(stream, DataFormats.Xaml, true);
         stream.Flush();
         stream.Position = 0L;
         using (StreamReader reader = new StreamReader(stream))
         {
             str = reader.ReadToEnd();
         }
     }
     if (!string.IsNullOrEmpty(str))
     {
         string str2 = ReplaceControls.ReplaceGUIWithClipboardControl(str, selection.Start, selection.End);
         if (!string.IsNullOrEmpty(str2) && (str2 != str))
         {
             e.DataObject.SetData(BamaDataFormat, str2);
         }
     }
 }
开发者ID:QuocHuy7a10,项目名称:Arianrhod,代码行数:24,代码来源:ClipboardMgr.cs

示例11: ResponseHeadersTextChanged

        private void ResponseHeadersTextChanged()
        {
            if (HeaderResponse.Document == null) return;
            var documentRange = new TextRange(HeaderResponse.Document.ContentStart, HeaderResponse.Document.ContentEnd);
            documentRange.ClearAllProperties();

            TextPointer navigator = HeaderResponse.Document.ContentStart;
            while (navigator.CompareTo(HeaderResponse.Document.ContentEnd) < 0)
            {
                TextPointerContext context = navigator.GetPointerContext(LogicalDirection.Backward);
                if (context == TextPointerContext.ElementStart && navigator.Parent is Run)
                {
                    CheckHeaderWordsInRun((Run)navigator.Parent);
                }
                navigator = navigator.GetNextContextPosition(LogicalDirection.Forward);
            }
            FormatHeaders();
        }
开发者ID:seanmcalinden,项目名称:restbox,代码行数:18,代码来源:HttpRequest.xaml.cs

示例12: ClearHighlighting

        private void ClearHighlighting(FrameworkElement container)
        {
            var searchFields = container?.ChildrenOfType<TextBlock>();
            if (searchFields == null || searchFields.Count == 0)
            {
                return;
            }

            foreach (var field in searchFields)
            {
                var contentRange = new TextRange(field.ContentStart, field.ContentEnd);
                contentRange.ClearAllProperties();
            }
        }
开发者ID:abdelkarim,项目名称:TokenEdit,代码行数:14,代码来源:TokenEdit.cs

示例13: ToggleContainerVisibility

        private void ToggleContainerVisibility(FrameworkElement container, TokenInfo tokenInfo)
        {
            if (container == null || tokenInfo == null)
            {
                return;
            }

            var searchFields = container.ChildrenOfType<TextBlock>();
            if (searchFields == null || searchFields.Count <= 0)
            {
                tokenInfo.Visibility = Visibility.Collapsed;
                return;
            }

            var isFilterContained = false;
            var highlightingForeground = HighlightingForeground;
            var highlightingBackground = this.HighlightingBackground;

            foreach (var field in searchFields)
            {
                if (TokenEditExtensions.GetIsExcludedFromSearch(field))
                {
                    continue;
                }

                // clear any previously applied formatting
                var contentRange = new TextRange(field.ContentStart, field.ContentEnd);
                contentRange.ClearAllProperties();

                var matches = Regex.Matches(field.Text, Filter, RegexOptions.IgnoreCase);
                if (matches.Count == 0)
                {
                    continue;
                }

                isFilterContained = true;
                foreach (Match match in matches)
                {
                    var textRange = field.GetTextRangeFromCharOffset(match.Index, match.Length);
                    textRange.ApplyPropertyValue(TextElement.BackgroundProperty, highlightingBackground);

                    if (highlightingForeground != null)
                    {
                        textRange.ApplyPropertyValue(TextElement.ForegroundProperty, highlightingForeground);
                    }
                }
            }

            tokenInfo.Visibility = isFilterContained ? Visibility.Visible : Visibility.Collapsed;
        }
开发者ID:abdelkarim,项目名称:TokenEdit,代码行数:50,代码来源:TokenEdit.cs

示例14: FormatTextRange

        public static void FormatTextRange(TextRange range, Row row)
        {
            range.ClearAllProperties();

            if (!row.HasText)
            {
                return;
            }

            if (row.IsCompleted)
            {
                range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Gray);
                range.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic);
                return;
            }

            TextPointer start = range.Start;

            if (row.HasPriority)
            {
                TextPointer priorityStart = GetTextPointAtOffset(start, row.PriorityRange.Item1);
                TextPointer priorityEnd = GetTextPointAtOffset(start, row.PriorityRange.Item2);
                TextRange priorityRange = new TextRange(priorityStart, priorityEnd);

                priorityRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                priorityRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);
            }

            if (row.HasCreationDate)
            {
                TextPointer dateStart = GetTextPointAtOffset(start, row.CreationDateRange.Item1);
                TextPointer dateEnd = GetTextPointAtOffset(start, row.CreationDateRange.Item2);
                TextRange dateRange = new TextRange(dateStart, dateEnd);

                dateRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                dateRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkGreen);
            }

            if (row.HasContexts)
            {
                foreach (Tuple<int, int> contextRange in row.ContextRanges)
                {
                    TextPointer contextStart = GetTextPointAtOffset(start, contextRange.Item1);
                    TextPointer contextEnd = GetTextPointAtOffset(start, contextRange.Item2);
                    TextRange contextTextRange = new TextRange(contextStart, contextEnd);

                    contextTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                    contextTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkCyan);
                }
            }

            if (row.HasProjects)
            {
                foreach (Tuple<int, int> projectRange in row.ProjectRanges)
                {
                    TextPointer projectStart = GetTextPointAtOffset(start, projectRange.Item1);
                    TextPointer projectEnd = GetTextPointAtOffset(start, projectRange.Item2);
                    TextRange projectTextRange = new TextRange(projectStart, projectEnd);

                    projectTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                    projectTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.SaddleBrown);
                }
            }
        }
开发者ID:jcheng31,项目名称:todoPad,代码行数:64,代码来源:TaskParser.cs

示例15: Highlight

 private void Highlight()
 {
     InputEditor.Background = Brushes.Black;
     var existingRange = new TextRange(InputEditor.Document.ContentStart, InputEditor.Document.ContentEnd);
     existingRange.ClearAllProperties();
     var navigator = InputEditor.Document.ContentStart;
     while (navigator.CompareTo(InputEditor.Document.ContentEnd) < 0)
     {
         var context = navigator.GetPointerContext(LogicalDirection.Backward);
         if (context == TextPointerContext.ElementStart && navigator.Parent is Run)
         {
             CheckWordsInRun((Run) navigator.Parent);
         }
         navigator = navigator.GetNextContextPosition(LogicalDirection.Forward);
     }
     Format();
 }
开发者ID:lynchjames,项目名称:bdUnit,代码行数:17,代码来源:bdUnitPreviewWindow.xaml.cs


注:本文中的System.Windows.Documents.TextRange.ClearAllProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。