Beispiel #1
0
        /// <summary>
        /// ToggleUnderline command event handler.
        /// </summary>
        private static void OnToggleUnderline(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor This = TextEditor._GetTextEditor(target);

            if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection))
            {
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            object propertyValue = ((TextSelection)This.Selection).GetCurrentValue(Inline.TextDecorationsProperty);
            TextDecorationCollection textDecorations = propertyValue != DependencyProperty.UnsetValue ? (TextDecorationCollection)propertyValue : null;

            TextDecorationCollection toggledTextDecorations;

            if (!TextSchema.HasTextDecorations(textDecorations))
            {
                toggledTextDecorations = TextDecorations.Underline;
            }
            else if (!textDecorations.TryRemove(TextDecorations.Underline, out toggledTextDecorations))
            {
                // TextDecorations.Underline was not present, so add it
                toggledTextDecorations.Add(TextDecorations.Underline);
            }

            TextEditorCharacters._OnApplyProperty(This, Inline.TextDecorationsProperty, toggledTextDecorations);
        }
        // Token: 0x06003839 RID: 14393 RVA: 0x000FAC48 File Offset: 0x000F8E48
        private static void OnToggleUnderline(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(target);

            if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection is TextSelection))
            {
                return;
            }
            TextEditorTyping._FlushPendingInputItems(textEditor);
            object currentValue = ((TextSelection)textEditor.Selection).GetCurrentValue(Inline.TextDecorationsProperty);
            TextDecorationCollection textDecorationCollection = (currentValue != DependencyProperty.UnsetValue) ? ((TextDecorationCollection)currentValue) : null;
            TextDecorationCollection underline;

            if (!TextSchema.HasTextDecorations(textDecorationCollection))
            {
                underline = TextDecorations.Underline;
            }
            else if (!textDecorationCollection.TryRemove(TextDecorations.Underline, out underline))
            {
                underline.Add(TextDecorations.Underline);
            }
            TextEditorCharacters._OnApplyProperty(textEditor, Inline.TextDecorationsProperty, underline);
        }