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


C# TextRange.GetPropertyValue方法代码示例

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


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

示例1: IsItalic

        public static bool? IsItalic(TextRange range)
        {
            if (range.GetPropertyValue(Control.FontStyleProperty) == DependencyProperty.UnsetValue)
                return null;

            return (FontStyle)range.GetPropertyValue(MyEdit.FontStyleProperty) == FontStyles.Italic;
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:7,代码来源:TextRangeHelpers.cs

示例2: IsBold

        public static bool? IsBold(TextRange range)
        {
            if (range.GetPropertyValue(MyEdit.FontWeightProperty) == DependencyProperty.UnsetValue)
                return null;

            return (FontWeight)range.GetPropertyValue(MyEdit.FontWeightProperty) == FontWeights.Bold;
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:7,代码来源:TextRangeHelpers.cs

示例3: cmdBold_Click

        private void cmdBold_Click(object sender, RoutedEventArgs e)
        {
            if (richTextBox.Selection.Text == "")
            {
                FontWeight fontWeight = richTextBox.Selection.Start.Paragraph.FontWeight;
                if (fontWeight == FontWeights.Bold)
                    fontWeight = FontWeights.Normal;
                else
                    fontWeight = FontWeights.Bold;

                richTextBox.Selection.Start.Paragraph.FontWeight = fontWeight;
            }
            else
            {
            Object obj = richTextBox.Selection.GetPropertyValue(TextElement.FontWeightProperty);
            if (obj == DependencyProperty.UnsetValue)
            {
                TextRange range = new TextRange(richTextBox.Selection.Start,
                    richTextBox.Selection.Start);
                obj = range.GetPropertyValue(TextElement.FontWeightProperty);
            }

            FontWeight fontWeight = (FontWeight)obj;

            if (fontWeight == FontWeights.Bold)
              fontWeight = FontWeights.Normal;
            else
              fontWeight = FontWeights.Bold;

            richTextBox.Selection.ApplyPropertyValue(
              TextElement.FontWeightProperty, fontWeight);
            }
        }
开发者ID:ittray,项目名称:LocalDemo,代码行数:33,代码来源:RichTextEditor.xaml.cs

示例4: GetTextDecorationOnSelection

        public static bool? GetTextDecorationOnSelection(TextRange range, TextDecorationLocation decorationLocation)
        {
            if (range.GetPropertyValue(TextBlock.TextDecorationsProperty) == DependencyProperty.UnsetValue)
                return null;

            TextDecorationCollection decorations = (TextDecorationCollection)range.GetPropertyValue(TextBlock.TextDecorationsProperty);

            if (decorations == null)
                return false;

            foreach (TextDecoration decoration in decorations)
            {
                if (decoration.Location == decorationLocation)
                    return true;
            }

            return false;
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:18,代码来源:TextRangeHelpers.cs

示例5: FontProperties

 public FontProperties(TextRange range)
 {
     __FontWeight = range.GetPropertyValue(RichTextBox.FontWeightProperty);
     __FontSize = range.GetPropertyValue(RichTextBox.FontSizeProperty);
     __FontStyle = range.GetPropertyValue(RichTextBox.FontStyleProperty);
     __TextDecorations = range.GetPropertyValue(TextBlock.TextDecorationsProperty) as TextDecorationCollection;
     __FontFamily = range.GetPropertyValue(RichTextBox.FontFamilyProperty) as FontFamily;
     __ForegroundColor = range.GetPropertyValue(RichTextBox.ForegroundProperty) as Brush;
 }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:9,代码来源:FontProperties.cs

示例6: SendTheMessageToRichTextBox

        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = this.TargetRichTextBox;

            TextRange tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);
            tr.Text = logMessage + "\n";
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            //int startIndex = rtbx.Text.Length;
            //rtbx.SelectionStart = startIndex;
            //rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            //rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            //rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            //rtbx.AppendText(logMessage + "\n");
            //rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            //// find word to color
            //foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            //{
            //    MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
            //    foreach (Match m in mc)
            //    {
            //        rtbx.SelectionStart = m.Index;
            //        rtbx.SelectionLength = m.Length;
            //        rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
            //        rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
            //        rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
            //    }
            //}

            if (this.MaxLines > 0)
            {
                this.lineCount++;
                if (this.lineCount > this.MaxLines)
                {
                    tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
                    tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                    this.lineCount--;
                }
            }

            if (this.AutoScroll)
            {
                //rtbx.Select(rtbx.TextLength, 0);
                rtbx.ScrollToEnd();
            }
        }
开发者ID:unicloud,项目名称:AFRP,代码行数:54,代码来源:WpfRichTextBoxTarget.cs

示例7: SetToolbar

        /// <summary>
        /// Sets the toolbar.
        /// </summary>
        private void SetToolbar()
        {
            // Set font family combo
            var textRange = new TextRange(TextBox.Selection.Start, TextBox.Selection.End);
            var fontFamily = textRange.GetPropertyValue(TextElement.FontFamilyProperty);
            FontFamilyCombo.SelectedItem = fontFamily;

            // Set font size combo
            var fontSize = textRange.GetPropertyValue(TextElement.FontSizeProperty);
            FontSizeCombo.Text = fontSize.ToString();

            // Set Font buttons
            if (!String.IsNullOrEmpty(textRange.Text))
            {
                BoldButton.IsChecked = textRange.GetPropertyValue(TextElement.FontWeightProperty).Equals(FontWeights.Bold);
                ItalicButton.IsChecked = textRange.GetPropertyValue(TextElement.FontStyleProperty).Equals(FontStyles.Italic);
                var prop = textRange.GetPropertyValue(Inline.TextDecorationsProperty);
                if( prop!= null)
                    UnderlineButton.IsChecked = textRange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Underline);
            }

            // Set Alignment buttons
            LeftButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Left);
            CenterButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Center);
            RightButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Right);
            JustifyButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Justify);
        }
开发者ID:b4p3p,项目名称:omeopauta,代码行数:30,代码来源:FsRichTextBox.xaml.cs

示例8: UpdateFontSettings

        private void UpdateFontSettings(TextRange range)
        {
            double fontSize = -1;
            if (range.GetPropertyValue(TextBlock.FontSizeProperty) != DependencyProperty.UnsetValue)
                fontSize = (double)range.GetPropertyValue(TextBlock.FontSizeProperty);

            FontFamily fontFamily = range.GetPropertyValue(Run.FontFamilyProperty) as FontFamily;

            __FontParametersChanging = true;
            try
            {
                TextSettingsSetFontSize(fontSize);
                TextSettingsSetFontFamily(fontFamily);
            }
            finally
            {
                __FontParametersChanging = false;
            }

            SolidColorBrush fontBrush = Brushes.Black;
            if (range.GetPropertyValue(ForegroundProperty) != DependencyProperty.UnsetValue)
                fontBrush = (SolidColorBrush)range.GetPropertyValue(ForegroundProperty);

            SelectColorBorder.Background = fontBrush;

            FontBold.IsChecked = TextRangeHelpers.IsBold(range);
            FontItalic.IsChecked = TextRangeHelpers.IsItalic(range);
            FontUnderline.IsChecked = TextRangeHelpers.GetTextDecorationOnSelection(range, TextDecorationLocation.Underline);
            FontStrikethrough.IsChecked = TextRangeHelpers.GetTextDecorationOnSelection(range, TextDecorationLocation.Strikethrough);
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:30,代码来源:MainWindow.xaml.cs

示例9: SelectColor

        private SolidColorBrush SelectColor(MyEdit edit, TextRange range)
        {
            SolidColorBrush currentBrush = Brushes.Black;
            SolidColorBrush newBrush = null;
            if (range.GetPropertyValue(ForegroundProperty) != DependencyProperty.UnsetValue)
            {
                currentBrush = (SolidColorBrush)range.GetPropertyValue(ForegroundProperty);
            }

            ColorPickerDialog colorPicker = new ColorPickerDialog();
            colorPicker.Owner = this;

            colorPicker.cPicker.SelectedColor = currentBrush.Color;
            if (colorPicker.ShowDialog() == true)
            {
                newBrush = new SolidColorBrush(colorPicker.cPicker.SelectedColor);
                if (edit != null)
                {
                    edit.ApplyUndoAwarePropertyValue(range, ForegroundProperty, newBrush);
                }
                else
                {

                    ApplyUndoEnabledPropertyValue(OutlinerTree.SelectedItem, ForegroundProperty, newBrush);
                }
            }

            UpdateFontSettings(range);
            return newBrush;
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:30,代码来源:MainWindow.xaml.cs

示例10: ProcessSelectionChanged

        /// <summary>
        /// Processes selection changed event.
        /// </summary>
        private void ProcessSelectionChanged()
        {
            if (this.htmlEditorViewModel == null)
                return;

            TextRange tr = new TextRange(this.Selection.Start, this.Selection.End);
            if (tr.GetPropertyValue(FontWeightProperty).ToString() == "Bold")
            {
                if (!this.htmlEditorViewModel.IsSelectionTextBold)
                    this.htmlEditorViewModel.IsSelectionTextBold = true;
            }
            else
            {
                if (this.htmlEditorViewModel.IsSelectionTextBold)
                    this.htmlEditorViewModel.IsSelectionTextBold = false;
            }

            if (tr.GetPropertyValue(FontStyleProperty).ToString() == "Italic")
            {
                if (!htmlEditorViewModel.IsSelectionTextItalic)
                    this.htmlEditorViewModel.IsSelectionTextItalic = true;
            }
            else
            {
                if (htmlEditorViewModel.IsSelectionTextItalic)
                    this.htmlEditorViewModel.IsSelectionTextItalic = false;
            }

            bool bHandledUnderline = false;
            TextDecorationCollection col = tr.GetPropertyValue(Inline.TextDecorationsProperty) as TextDecorationCollection;
            if (col != null)
            {

                foreach (TextDecoration decoration in col)
                    if (decoration == TextDecorations.Underline[0])
                    {
                        bHandledUnderline = true;
                        if (!this.htmlEditorViewModel.IsSelectionTextUnderlined)
                            this.htmlEditorViewModel.IsSelectionTextUnderlined = true;
                        break;
                    }
            }
            if (!bHandledUnderline)
                if (this.htmlEditorViewModel.IsSelectionTextUnderlined)
                    this.htmlEditorViewModel.IsSelectionTextUnderlined = false;

            // alignment
            object alignmentObj = tr.GetPropertyValue(Paragraph.TextAlignmentProperty);
            if (alignmentObj != null)
            {
                TextAlignment alignment = (TextAlignment)alignmentObj;
                bool bAlignLeft = false;
                bool bAlignCenter = false;
                bool bAlignRight = false;
                bool bAlignJustify = false;
                if (alignment == System.Windows.TextAlignment.Left)
                    bAlignLeft = true;
                else if (alignment == System.Windows.TextAlignment.Center)
                    bAlignCenter = true;
                else if (alignment == System.Windows.TextAlignment.Right)
                    bAlignRight = true;
                else if (alignment == System.Windows.TextAlignment.Justify)
                    bAlignJustify = true;

                if (htmlEditorViewModel.IsSelectionAlignedLeft != bAlignLeft)
                    htmlEditorViewModel.IsSelectionAlignedLeft = bAlignLeft;
                if (htmlEditorViewModel.IsSelectionAlignedCenter != bAlignCenter)
                    htmlEditorViewModel.IsSelectionAlignedCenter = bAlignCenter;
                if (htmlEditorViewModel.IsSelectionAlignedRight != bAlignRight)
                    htmlEditorViewModel.IsSelectionAlignedRight = bAlignRight;
                if (htmlEditorViewModel.IsSelectionAlignedJustified != bAlignJustify)
                    htmlEditorViewModel.IsSelectionAlignedJustified = bAlignJustify;
            }

            updateSelectionPropertiesPending = false;
        }
开发者ID:apoorv-vijay-joshi,项目名称:FSE-2011-PDE,代码行数:79,代码来源:HtmlRichTextEditor.cs

示例11: SetToolbar

        /// <summary>
        /// Sets the toolbar.
        /// </summary>
        private void SetToolbar()
        {
            // Set font family combo
            var textRange = new TextRange(TextBox.Selection.Start, TextBox.Selection.End);
            var fontFamily = textRange.GetPropertyValue(TextElement.FontFamilyProperty);
            FontFamilyCombo.SelectedItem = fontFamily.ToString();   // @EDITED only works with the string representation

            // Set font size combo
            if (textRange.GetPropertyValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue) {
                var fontSize = textRange.GetPropertyValue(TextElement.FontSizeProperty);
                FontSizeCombo.Text = fontSize.ToString();
            }
            else {
                FontSizeCombo.Text = "";
            }

            // Set Font buttons @TODO FIX => doesn't work
            if (!String.IsNullOrEmpty(textRange.Text))
            {
                BoldButton.IsChecked = textRange.GetPropertyValue(TextElement.FontWeightProperty).Equals(FontWeights.Bold);
                ItalicButton.IsChecked = textRange.GetPropertyValue(TextElement.FontStyleProperty).Equals(FontStyles.Italic);
                UnderlineButton.IsChecked = textRange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Underline);
            }

            // Set Alignment buttons
            LeftButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Left);
            CenterButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Center);
            RightButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Right);
            JustifyButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Justify);

            // @EDITED Set font color chip
            if (textRange.GetPropertyValue(ForegroundProperty) != DependencyProperty.UnsetValue) {
                // Set the selected text's color as current chip color (converting hex to rgb).
                // WPF contains a built-in value converter that will recognize the ForegroundProperty's hex as a SolidColorBrush.
                var brush = (SolidColorBrush)(textRange.GetPropertyValue(ForegroundProperty));
                fontColor.Color = brush.Color;  // rgb color of the brush
            }
            else {
                // If multicolored text is selected set a neutral chip color (transparent)
                fontColor.Color = Color.FromArgb(0, 0, 0, 0);
            }
        }
开发者ID:sadeniju,项目名称:WpfExperiments,代码行数:45,代码来源:FsRichTextBox.xaml.cs

示例12: SetTextDecorationOnSelection

        public static void SetTextDecorationOnSelection(TextRange range, TextDecorationLocation decorationLocation, TextDecorationCollection newTextDecorations, bool value)
        {
            TextDecorationCollection decorations = new TextDecorationCollection();
            if (range.GetPropertyValue(TextBlock.TextDecorationsProperty) != DependencyProperty.UnsetValue)
            {
                TextDecorationCollection oldDecorations = (TextDecorationCollection)range.GetPropertyValue(TextBlock.TextDecorationsProperty);
                if (oldDecorations != null)
                    decorations.Add(oldDecorations);
            }

            if (value == true)
            {
                bool underlineAlreadyFound = false;
                foreach (TextDecoration decoration in decorations)
                {
                    if (decoration.Location == decorationLocation)
                    {
                        underlineAlreadyFound = true;
                        break;
                    }
                }

                if (!underlineAlreadyFound)
                {
                    decorations.Add(newTextDecorations);
                    range.ApplyPropertyValue(TextBlock.TextDecorationsProperty, decorations);
                }
            }
            else
            {
                for (int i = 0; i < decorations.Count; i++)
                {
                    if (decorations[i].Location == decorationLocation)
                    {
                        decorations.RemoveAt(i);
                        break;
                    }
                }

                range.ApplyPropertyValue(TextBlock.TextDecorationsProperty, decorations);
            }
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:42,代码来源:TextRangeHelpers.cs

示例13: HasSameStyle

        public bool HasSameStyle(TextRange range)
        {
            if (CompareBrushes(__ForegroundColor, range.GetPropertyValue(TextBlock.ForegroundProperty) as Brush))
                return false;

            if (__FontWeight != range.GetPropertyValue(RichTextBox.FontWeightProperty))
                return false;

            if (__FontSize != range.GetPropertyValue(RichTextBox.FontSizeProperty))
                return false;

            if (__FontStyle != range.GetPropertyValue(RichTextBox.FontStyleProperty))
                return false;

            if (CompareDecorations(__TextDecorations, range.GetPropertyValue(TextBlock.TextDecorationsProperty) as TextDecorationCollection))
                return false;

            if (__FontFamily != range.GetPropertyValue(RichTextBox.FontFamilyProperty))
                return false;

            return true;
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:22,代码来源:FontProperties.cs

示例14: SendTheMessageToRichTextBox

        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = TargetRichTextBox;

            var scrolledToEnd =
                AutoScroll
                && (TargetRichTextBox.VerticalOffset + TargetRichTextBox.ViewportHeight) >= (TargetRichTextBox.ExtentHeight - .1);

            var tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);
            tr.Text = logMessage + "\n";
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            if (MaxLines > 0)
            {
                while (rtbx.Document.Blocks.Count - 1 > MaxLines)
                {
                    rtbx.Document.Blocks.Remove(rtbx.Document.Blocks.FirstBlock);
                }
            }

            if (AutoScroll && scrolledToEnd)
            {
                rtbx.ScrollToEnd();
            }
        }
开发者ID:pmlyon,项目名称:BitSharp,代码行数:32,代码来源:WpfRichTextBoxTarget.cs

示例15: GetCell

        public BufferCell GetCell(TextPointer position, LogicalDirection direction)
        {
            TextRange range = null;
            try
            {
                range = new TextRange(position, position.GetPositionAtOffset(1, direction));

                return new BufferCell(
                        (range.IsEmpty || range.Text[0] == '\n') ? ' ' : range.Text[0],
                        ConsoleColorFromBrush((Brush)range.GetPropertyValue(TextElement.ForegroundProperty)),
                        ConsoleColorFromBrush((Brush)range.GetPropertyValue(TextElement.BackgroundProperty)),
                        BufferCellType.Complete);
            }
            catch
            {
                return new BufferCell();
            }
        }
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:18,代码来源:ConsoleTextBox.cs


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