コード例 #1
0
 private void fontFamilyBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0 && fontFamilyBox.SelectedItem != null)
     {
         TextEditing.SetRTBValue(FontFamilyProperty, fontFamilyBox.SelectedItem.ToString(), true);
     }
 }
コード例 #2
0
        private void UpdateFontSize(bool focusRTB)
        {
            string text = fontSizeBox.Text;

            double value;

            if (double.TryParse(text, out value))
            {
                TextEditing.SetRTBValue(FontSizeProperty, Converter.PixelToPoint(value), focusRTB, _rtb);

                bool found = false;

                foreach (ComboBoxItem each in fontSizeBox.Items)
                {
                    if (each.Content.ToString() == text)
                    {
                        each.IsSelected = true;
                        found           = true;
                        break;
                    }
                }

                if (!found)
                {
                    fontSizeBox.SelectedIndex = -1;
                    fontSizeBox.Text          = text;
                }
            }
        }
コード例 #3
0
        private void UpdateFormattingUI(RichTextBox rtb)
        {
            object font = TextEditing.GetRTBValue(TextElement.FontFamilyProperty, rtb);

            if (font != DependencyProperty.UnsetValue)
            {
                fontFamilyBox.IsTextSearchEnabled = true;
                fontFamilyBox.Text = font.ToString();
                fontFamilyBox.IsTextSearchEnabled = false;
            }
            else
            {
                fontFamilyBox.Text          = "";
                fontFamilyBox.SelectedIndex = -1;
            }

            object fontSize = TextEditing.GetRTBValue(TextElement.FontSizeProperty, rtb);

            if (fontSize != DependencyProperty.UnsetValue)
            {
                fontSizeBox.IsTextSearchEnabled = true;
                fontSizeBox.Text = Converter.PointToPixel((double)(fontSize)).ToString();
                fontSizeBox.IsTextSearchEnabled = false;
            }
            else
            {
                fontSizeBox.Text          = "";
                fontSizeBox.SelectedIndex = -1;
            }

            object fontWeight = TextEditing.GetRTBValue(FontWeightProperty, rtb);

            boldButton.IsChecked = fontWeight != DependencyProperty.UnsetValue ? (FontWeight)fontWeight == FontWeights.Bold : false;

            object fontStyle = TextEditing.GetRTBValue(FontStyleProperty, rtb);

            italicButton.IsChecked = fontStyle != DependencyProperty.UnsetValue ? (FontStyle)fontStyle == FontStyles.Italic : false;

            object textdecoration = TextEditing.GetRTBValue(TextBlock.TextDecorationsProperty, rtb);

            underlineButton.IsChecked     = TextEditing.ContainsTextDecoration(textdecoration, TextDecorations.Underline);
            strikethroughButton.IsChecked = TextEditing.ContainsTextDecoration(textdecoration, TextDecorations.Strikethrough);

            object color = TextEditing.GetRTBValue(ForegroundProperty);

            if (color != DependencyProperty.UnsetValue)
            {
                fontColor.ActiveColor = (Brush)color;
            }

            object highlight = TextEditing.GetRTBValue(TextElement.BackgroundProperty);

            if (highlight != DependencyProperty.UnsetValue)
            {
                highlightColor.ActiveColor = (Brush)highlight;
            }

            UpdateSelectionListType(rtb);
        }
コード例 #4
0
        private void clearFormatting_Click(object sender, RoutedEventArgs e)
        {
            _rtb.BeginChange();

            _rtb.Selection.ClearAllProperties();
            _rtb.Selection.ApplyPropertyValue(Paragraph.MarginProperty, new Thickness(0));
            TextEditing.ChangeRTBParagraphBackground(_rtb, null);

            _rtb.EndChange();

            UpdateFormattingUI(_rtb);
        }
コード例 #5
0
        private static void ExecutedStrikethroughCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ContextTextFormatter formatter = (ContextTextFormatter)sender;

            if (formatter.strikethroughButton.IsChecked == true)
            {
                TextEditing.AddTextDecoration(TextDecorations.Strikethrough);
            }
            else
            {
                TextEditing.RemoveTextDecoration(TextDecorations.Strikethrough);
            }
        }
コード例 #6
0
        private static void ExecutedUnderlineCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ContextTextFormatter formatter = (ContextTextFormatter)sender;

            if (formatter.underlineButton.IsChecked == true)
            {
                TextEditing.AddTextDecoration(TextDecorations.Underline);
            }
            else
            {
                TextEditing.RemoveTextDecoration(TextDecorations.Underline);
            }
        }
コード例 #7
0
        private void fontSizeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                string newSize = (string)((ContentControl)fontSizeBox.SelectedItem).Content;

                double value;

                if (double.TryParse(newSize, out value))
                {
                    TextEditing.SetRTBValue(FontSizeProperty, Converter.PixelToPoint(value), true);
                }
            }
        }
コード例 #8
0
        private void UpdateFontFamily(bool focusRTB)
        {
            string text = fontFamilyBox.Text;

            TextEditing.SetRTBValue(FontFamilyProperty, text, focusRTB, _rtb);

            bool found = false;

            for (int i = 0; i < fontFamilyBox.Items.Count; i++)
            {
                if (fontFamilyBox.Items[i].ToString() == text)
                {
                    fontFamilyBox.SelectedIndex = i;
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                fontFamilyBox.SelectedIndex = -1;
                fontFamilyBox.Text          = text;
            }
        }
コード例 #9
0
 private void highlightColor_OnSelectedChangedEvent(object sender, EventArgs e)
 {
     TextEditing.SetRTBValue(TextElement.BackgroundProperty, highlightColor.SelectedColor, true, _rtb);
 }
コード例 #10
0
 private void fontColor_OnSelectedChangedEvent(object sender, EventArgs e)
 {
     TextEditing.SetRTBValue(ForegroundProperty, fontColor.SelectedColor, true, _rtb);
 }