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


C# TextRange.ApplyPropertyValue方法代码示例

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


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

示例1: Update

        public void Update()
        {
            ChatText.Document.Blocks.Clear();
            ChatPlayerItem tempItem = null;
            foreach (KeyValuePair<string, ChatPlayerItem> x in Client.AllPlayers)
            {
                if (x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content)
                {
                    tempItem = x.Value;
                    break;
                }
            }

            foreach (string x in tempItem.Messages.ToArray())
            {
                string[] Message = x.Split('|');
                TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd);
                if (Message[0] == tempItem.Username)
                {
                    tr.Text = tempItem.Username + ": ";
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Gold);
                }
                else
                {
                    tr.Text = Message[0] + ": ";
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.SteelBlue);
                }
                tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd);
                tr.Text = x.Replace(Message[0] + "|", "") + Environment.NewLine;
                tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
            }

            ChatText.ScrollToEnd();
        }
开发者ID:JizzHub,项目名称:LegendaryClient,代码行数:34,代码来源:ChatItem.xaml.cs

示例2: 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

示例3: Format

 public void Format()
 {
     for (int i = 0; i < _ranges.Count; i++)
     {
         TextRange range = new TextRange(_ranges[i].StartPosition, _ranges[i].EndPosition);
         range.ApplyPropertyValue(TextElement.ForegroundProperty, _ranges[i].Foreground);
         range.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
     }
     _ranges.Clear();
 }
开发者ID:MotorViper,项目名称:FormGenerator,代码行数:10,代码来源:RichTextBoxEditor.cs

示例4: AppendText

 /// <summary>
 /// Extension method for writing color to a RichTextBox.
 /// </summary>
 /// <param name="box">the RichTextBox to be written to.</param>
 /// <param name="text">the text to be written to the RichTextBox.</param>
 /// <param name="color">the color of the text, defined by the Color structure.</param>
 /// <param name="sameLine">True if the text is to be written to the same line as the last text.</param>
 public static void AppendText(this RichTextBox box, string text, string color, bool sameLine)
 {
     BrushConverter bc = new BrushConverter();
     TextRange tr = new TextRange(box.Document.ContentEnd, box.Document.ContentEnd);
     if (!sameLine)
         tr.Text = "\r\n" + text;
     else
         tr.Text = text;
     try { tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString(color)); }
     catch (FormatException) { tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString("Black")); }
 }
开发者ID:sapeornis,项目名称:Realm2,代码行数:18,代码来源:Extensions.cs

示例5: ApplyToRange

 public virtual void ApplyToRange(TextRange range, IConsoleColorMap colorMap)
 {
     if (DefaultBackground != null)
     {
         range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(colorMap.MapBackground(DefaultBackground.Value)));
     }
     if (DefaultForeground != null)
     {
         range.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(colorMap.MapBackground(DefaultForeground.Value)));
     }
 }
开发者ID:anurse,项目名称:Coco,代码行数:11,代码来源:TextClassification.cs

示例6: TextFormatter

        public TextFormatter(string message)
        {
            IsPage = IsWhisper = IsNotify = false;

            FormattedRun = new Run(message);

            if (page.IsMatch(message))
            {
                TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd);

                range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkGreen);
                range.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.ExtraBold);

                IsPage = true;
            }
            else if (whisper.IsMatch(message))
            {
                TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd);

                range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkBlue);
                range.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic);

                IsWhisper = true;
            }
            else if (message[0] == '#')
            {
                TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd);

                range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.LightGray);
            }
            else if (message[0] == '<')
            {
                TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd);

                range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
                range.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Cyan);
                range.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.ExtraBold);

                IsNotify = true;
            }
            else if (message.IndexOf("Somewhere on the muck") == 0)
            {
                TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd);

                range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkSlateGray);

                IsConnect = true;
            }
        }
开发者ID:kotarn,项目名称:TapsLite,代码行数:49,代码来源:TextFormatter.cs

示例7: Write

		public void Write (string s)
		{
			// Capture state locally
			var fore = _Fore;
			var back = _Back;

			_RTF.Dispatcher.BeginInvoke ((Action) (() => {
				var range = new TextRange (_RTF.Document.ContentEnd, _RTF.Document.ContentEnd);
				range.Text = s;
				range.ApplyPropertyValue (TextElement.ForegroundProperty, new SolidColorBrush (fore));
				range.ApplyPropertyValue (TextElement.BackgroundProperty, new SolidColorBrush (back));

				_RTF.ScrollToEnd ();
			}));
		}
开发者ID:nerai,项目名称:Unlog,代码行数:15,代码来源:WpfRtfLogTarget.cs

示例8: LogTextChanged

        // Event handler
        void LogTextChanged(object sender, TextChangedEventArgs e)
        {
            RichTextBox textView = (RichTextBox)sender;
            TextRange completeContent = new TextRange(textView.Document.ContentStart, textView.Document.ContentEnd);
            string logContent = completeContent.Text;

            // highlight the text to search
            if (FindLogTextBox.Text.Length > 0)
            {
                // http://msdn.microsoft.com/en-us/library/system.windows.documents.textpointer.aspx
                TextPointer position = textView.Document.ContentStart;
                while (position != null)
                {
                    if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
                    {
                        string textRun = position.GetTextInRun(LogicalDirection.Forward);
                        int indexInRun = textRun.IndexOf(FindLogTextBox.Text);
                        if (indexInRun >= 0)
                        {
                            TextPointer start = position.GetPositionAtOffset(indexInRun);
                            TextPointer end = start.GetPositionAtOffset(FindLogTextBox.Text.Length);
                            var textRange = new TextRange(start, end);
                            textRange.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Red);
                        }
                    }
                    position = position.GetNextContextPosition(LogicalDirection.Forward);
                }
            }
        }
开发者ID:RELOAD-NET,项目名称:RELOAD.NET,代码行数:30,代码来源:MainWindow.xaml.cs

示例9: TypefaceListItem

        public TypefaceListItem(Typeface typeface)
        {
            _displayName = GetDisplayName(typeface);
            _simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated;

            FontFamily = typeface.FontFamily;
            FontWeight = typeface.Weight;
            FontStyle = typeface.Style;
            FontStretch = typeface.Stretch;

            var itemLabel = _displayName;

            if (_simulated)
            {
                var formatString = Properties.Resources.ResourceManager.GetString(
                    "simulated",
                    CultureInfo.CurrentUICulture
                    );
                itemLabel = string.Format(formatString, itemLabel);
            }

            Text = itemLabel;
            ToolTip = itemLabel;

            // In the case of symbol font, apply the default message font to the text so it can be read.
            if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily))
            {
                var range = new TextRange(ContentStart, ContentEnd);
                range.ApplyPropertyValue(FontFamilyProperty, SystemFonts.MessageFontFamily);
            }
        }
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:31,代码来源:TypefaceListItem.cs

示例10: UserControl_IsVisibleChanged

        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.Visibility == Visibility.Visible)
            {
                // Show the story, hide the editor
                StoryViewBorder.Visibility = Visibility.Visible;
                StoryEditBorder.Visibility = Visibility.Hidden;

                // Load the person story into the viewer
                LoadStoryText(StoryViewer.Document);

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));

                // Hide the photo tags and photo edit buttons if there is no main photo.
                if (DisplayPhoto.Source == null)
                {
                    TagsStackPanel.Visibility = Visibility.Hidden;
                    PhotoButtonsDockPanel.Visibility = Visibility.Hidden;
                }

                // Workaround to get the StoryViewer to display the first page instead of the last page when first loaded
                StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
                StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page;
            }
        }
开发者ID:ssickles,项目名称:archive,代码行数:28,代码来源:PersonInfo.xaml.cs

示例11: XmppConnection_OnMessage

        void XmppConnection_OnMessage(object sender, Message msg)
        {
            if (!roomName.Contains(msg.From.User))
                return;

            if (msg.From.Resource == Client.LoginPacket.AllSummonerData.Summoner.Name)
                return;

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                if (msg.Body == "This room is not anonymous")
                    return;

                var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd)
                {
                    Text = msg.From.Resource + ": "
                };
                tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Turquoise);

                tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd)
                {
                    Text = msg.Body.Replace("<![CDATA[", "").Replace("]]>", string.Empty) + Environment.NewLine
                };
                tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);

                ChatText.ScrollToEnd();
            }));
        }
开发者ID:osiato,项目名称:LegendaryClient,代码行数:28,代码来源:GroupChatItem.xaml.cs

示例12: ShowLobbyMessage

 public void ShowLobbyMessage(string message) {
   var tr = new TextRange(output.Document.ContentEnd, output.Document.ContentEnd);
   tr.Text = message + '\n';
   tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
   if (scroller.VerticalOffset == scroller.ScrollableHeight)
     scroller.ScrollToBottom();
 }
开发者ID:mfro,项目名称:LeagueClient,代码行数:7,代码来源:ChatRoom.cs

示例13: appendErrorText

 /// <summary>
 /// Append text to RichTextBox with red coloring; for errors
 /// </summary>
 /// <param name="targetBox">Box to append text to</param>
 /// <param name="text">Error text to append</param>
 private void appendErrorText(RichTextBox targetBox, string text)
 {
     // Append text with automatic styling for error text
     TextRange tr = new TextRange(targetBox.Document.ContentEnd, targetBox.Document.ContentEnd);
     tr.Text = text;
     tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
 }
开发者ID:TheQuack45,项目名称:HypeBotCSharp-old,代码行数:12,代码来源:MainWindow.xaml.cs

示例14: RichTextBoxToolbar

        public RichTextBoxToolbar()
        {
            SpecialInitializeComponent();

            cmbFontFamily.SelectionChanged += (s, e) =>
            {
                if (cmbFontFamily.SelectedValue != null && RichTextBox != null)
                {
                    TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End);
                    var value = cmbFontFamily.SelectedValue;
                    tr.ApplyPropertyValue(TextElement.FontFamilyProperty, value);
                }
            };

            cmbFontSize.SelectionChanged += (s, e) =>
            {
                if (cmbFontSize.SelectedValue != null && RichTextBox != null)
                {
                    TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End);
                    var value = ((ComboBoxItem)cmbFontSize.SelectedValue).Content.ToString();
                    tr.ApplyPropertyValue(TextElement.FontSizeProperty, double.Parse(value));
                }
            };
            cmbFontSize.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler((s, e) =>
            {
                if (!string.IsNullOrEmpty(cmbFontSize.Text) && RichTextBox != null)
                {
                    TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End);
                    tr.ApplyPropertyValue(TextElement.FontSizeProperty, double.Parse(cmbFontSize.Text));
                }
            }));
        }
开发者ID:icsharpcode,项目名称:WpfDesigner,代码行数:32,代码来源:RichTextBoxToolbar.xaml.cs

示例15: TypefaceListItem

        public TypefaceListItem(Typeface typeface)
        {
            _displayName = GetDisplayName(typeface);
            _simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated;

            this.FontFamily = typeface.FontFamily;
            this.FontWeight = typeface.Weight;
            this.FontStyle = typeface.Style;
            this.FontStretch = typeface.Stretch;

            string itemLabel = _displayName;

            //if (_simulated)
            //{
            //    string formatString = EpiDashboard.Properties.Resources.ResourceManager.GetString(
            //        "simulated",
            //        CultureInfo.CurrentUICulture
            //        );
            //    itemLabel = string.Format(formatString, itemLabel);
            //}

            this.Text = itemLabel;
            this.ToolTip = itemLabel;

            // In the case of symbol font, apply the default message font to the text so it can be read.
            if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily))
            {
                TextRange range = new TextRange(this.ContentStart, this.ContentEnd);
                range.ApplyPropertyValue(TextBlock.FontFamilyProperty, SystemFonts.MessageFontFamily);
            }
        }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:31,代码来源:TypefaceListItem.cs


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