public static void LostFocus(ref RichTextBox rtb, ref ToolBarRtfFontStyle tbrFontStyle, ref ToolBarRtfStyle tbrStyle) { if (rtb == null || tbrFontStyle == null || tbrStyle == null || rtb.IsReadOnly) { return; } }
/// <summary> /// Modifica los controles segun el las propiedades del texto seleccionado /// </summary> /// <history> /// [jorcanche] created 20/08/2016 /// </history> public static void OnSalectionChanded(ref RichTextBox rtb, ref ToolBarRtfFontStyle tbrFontStyle, ref ToolBarRtfStyle tbrStyle) { if (rtb == null || tbrFontStyle == null || tbrStyle == null || rtb.IsReadOnly) { return; } _tbrFontStyle = tbrFontStyle; _tbrStyle = tbrStyle; rtb.LostFocus += LostFocusRichTextBox; //Font Family var fontFamily = rtb.Selection.GetPropertyValue(TextElement.FontFamilyProperty); if (fontFamily != null && fontFamily.ToString() != "{DependencyProperty.UnsetValue}") { tbrFontStyle.cbxfontFamilies.SelectedItem = fontFamily.GetType().GetProperty("Source").GetValue(fontFamily); } //Font Size var property = rtb.Selection.GetPropertyValue(TextElement.FontSizeProperty); double fontSize; if (property != null && double.TryParse(property.ToString(), out fontSize)) { var redondear = (int)Math.Round(fontSize); tbrFontStyle.cbxfontSize.SelectedItem = redondear; } //TextBold var textBold = rtb.Selection.GetPropertyValue(TextElement.FontWeightProperty); tbrStyle.imgTextBold.Background = textBold.Equals(FontWeights.Bold) ? Color : Brushes.White; //TextItalic var textItalic = rtb.Selection.GetPropertyValue(TextElement.FontStyleProperty); tbrStyle.imgTextItalic.Background = textItalic.Equals(FontStyles.Italic) ? Color : Brushes.White; //TextDecorations var textDecorations = rtb.Selection.GetPropertyValue(Inline.TextDecorationsProperty); //TextUnderLine tbrStyle.imgTextUnderLine.Background = textDecorations.Equals(TextDecorations.Underline) ? Color : Brushes.White; //TextStrikeOut tbrStyle.imgTextStrikeOut.Background = textDecorations.Equals(TextDecorations.Strikethrough) ? Color : Brushes.White; //TextAlignment var textAlignment = rtb.Selection.GetPropertyValue(FlowDocument.TextAlignmentProperty); //TextLeft tbrStyle.imgTextLeft.Background = textAlignment.Equals(TextAlignment.Left) ? Color : Brushes.White; //TextCenter tbrStyle.imgTextCenter.Background = textAlignment.Equals(TextAlignment.Center) ? Color : Brushes.White; //TextRight tbrStyle.imgTextRight.Background = textAlignment.Equals(TextAlignment.Right) ? Color : Brushes.White; //TextColor var textColor = rtb.Selection.GetPropertyValue(TextElement.ForegroundProperty).ToString(); if (textColor != "{DependencyProperty.UnsetValue}") { tbrStyle.imgColorPick.Background = textColor.Equals("#FF000000") ? Brushes.White : (SolidColorBrush) new BrushConverter().ConvertFrom(textColor); } }