Example #1
0
        public static void ApplyPropertyToRange(TextRange range, StylePropertyType propertyType, object value)
        {
            switch (propertyType)
            {
            case StylePropertyType.FontColor:
                range.ApplyPropertyValue(Run.ForegroundProperty, value);
                break;

            case StylePropertyType.FontSize:
                range.ApplyPropertyValue(Run.FontSizeProperty, (double)value);
                break;

            case StylePropertyType.IsBold:
                TextRangeHelpers.SetBold(range, (bool)value);
                break;

            case StylePropertyType.IsItalic:
                TextRangeHelpers.SetItalic(range, (bool)value);
                break;

            case StylePropertyType.IsStrike:
                TextRangeHelpers.SetTextDecorationOnSelection(range,
                                                              TextDecorationLocation.Strikethrough, TextDecorations.Strikethrough, (bool)value);
                break;

            case StylePropertyType.IsUnderlined:
                TextRangeHelpers.SetTextDecorationOnSelection(range,
                                                              TextDecorationLocation.Underline, TextDecorations.Underline, (bool)value);
                break;

            case StylePropertyType.Typeface:
                range.ApplyPropertyValue(Control.FontFamilyProperty, value);
                break;
            }
        }
Example #2
0
        public void UnapplyToRange(TextRange range)
        {
            foreach (LevelStyleProperty style in __StyleList)
            {
                switch (style.PropertyType)
                {
                case StylePropertyType.Typeface:
                    range.ApplyPropertyValue(Control.FontFamilyProperty, Settings.DefaultFontFamily);
                    break;

                case StylePropertyType.FontColor:
                    range.ApplyPropertyValue(Run.ForegroundProperty, Settings.DefaultFontColor);
                    break;

                case StylePropertyType.FontSize:
                    range.ApplyPropertyValue(Run.FontSizeProperty, Settings.DefaultFontSize);
                    break;

                case StylePropertyType.IsBold:
                    TextRangeHelpers.SetBold(range, false);
                    break;

                case StylePropertyType.IsItalic:
                    TextRangeHelpers.SetItalic(range, false);
                    break;

                case StylePropertyType.IsStrike:
                    TextRangeHelpers.SetTextDecorationOnSelection(range,
                                                                  TextDecorationLocation.Strikethrough, TextDecorations.Strikethrough, false);
                    break;

                case StylePropertyType.IsUnderlined:
                    TextRangeHelpers.SetTextDecorationOnSelection(range,
                                                                  TextDecorationLocation.Underline, TextDecorations.Underline, false);
                    break;
                }
            }
        }