private void paragraphSpacingBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { object fontSize = TextEditing.GetRTBValue(FontSizeProperty); if (fontSize == DependencyProperty.UnsetValue) { fontSize = SpellChecking.FocusedRTB.FontSize; } TextEditing.SetRTBValue(Paragraph.MarginProperty, new Thickness(0, 0, 0, (double.Parse((e.AddedItems[0] as ComboBoxItem).Content.ToString()) - 1) * (double)fontSize), true); } }
private void UpdateFormattingUI() { object font = TextEditing.GetRTBValue(TextElement.FontFamilyProperty); 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); 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); bold.IsChecked = fontWeight != DependencyProperty.UnsetValue ? (FontWeight)fontWeight == FontWeights.Bold : false; object fontStyle = TextEditing.GetRTBValue(FontStyleProperty); italic.IsChecked = fontStyle != DependencyProperty.UnsetValue ? (FontStyle)fontStyle == FontStyles.Italic : false; object textdecoration = TextEditing.GetRTBValue(TextBlock.TextDecorationsProperty); underline.IsChecked = TextEditing.ContainsTextDecoration(textdecoration, TextDecorations.Underline); strikethrough.IsChecked = TextEditing.ContainsTextDecoration(textdecoration, TextDecorations.Strikethrough); object variants = TextEditing.GetRTBValue(Typography.VariantsProperty); if (variants != DependencyProperty.UnsetValue) { switch ((FontVariants)variants) { case FontVariants.Subscript: subscript.IsChecked = true; break; case FontVariants.Superscript: superscript.IsChecked = true; break; default: subscript.IsChecked = false; superscript.IsChecked = false; break; } } else { subscript.IsChecked = false; superscript.IsChecked = false; } 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(); object alignment = TextEditing.GetRTBValue(TextBlock.TextAlignmentProperty); if (alignment != DependencyProperty.UnsetValue) { switch ((TextAlignment)alignment) { case TextAlignment.Center: alignCenter.IsChecked = true; break; case TextAlignment.Justify: alignJustify.IsChecked = true; break; case TextAlignment.Left: alignLeft.IsChecked = true; break; case TextAlignment.Right: alignRight.IsChecked = true; break; } } else { alignLeft.IsChecked = false; alignCenter.IsChecked = false; alignRight.IsChecked = false; alignJustify.IsChecked = false; } object margin = TextEditing.GetRTBValue(Paragraph.MarginProperty); double pSpacing = margin != DependencyProperty.UnsetValue ? ((Thickness)margin).Bottom : -1; if (fontSize == DependencyProperty.UnsetValue) { fontSize = SpellChecking.FocusedRTB.FontSize; } bool foundIndex = false; foreach (ComboBoxItem each in paragraphSpacingBox.Items) { if ((double.Parse(each.Content.ToString()) - 1) * (double)fontSize == pSpacing) { each.IsSelected = true; foundIndex = true; break; } } if (!foundIndex) { paragraphSpacingBox.SelectedIndex = -1; } object border = TextEditing.GetRTBValue(Block.BorderThicknessProperty); if (border != DependencyProperty.UnsetValue) { borderType.ActiveBorder = (Thickness)border; } object background = TextEditing.GetSelectionParagraphPropertyValue(SpellChecking.FocusedRTB.Selection, TextElement.BackgroundProperty); if (background != DependencyProperty.UnsetValue) { backgroundColor.ActiveColor = (Brush)background; } }