Highlight Colors Difference Between MS Word and RadRichTextBox
Environment
Product Version | 2024.2.514 |
Product | RadRichTextBox for WPF |
Description
The highlight colors that the RadRichTextBox control provides differ from the ones that are present in Microsoft Word. This cause the DOCX format to not use these additional colors when exporting a paragraph.
Solution
Change the colors of the color picker in the selection mini toolbar of the RadRichTextBox control. To do so, create a custom SelectionMiniToolBar
and override the OnApplyTemplate
method. In it, you can customize the colors of the MainPaletteItemsSource
property of the HighlightColorPicker
element.
The following example showcases this approach for a .NET Framework project. It will utilize the CustomSelectionMiniToolBar
attribute, which the MEF support will read and use this custom implementation:
Custom SelectionMiniToolBar for a .NET Framework project
[CustomSelectionMiniToolBar]
public class CustomSelectionMiniToolBar : SelectionMiniToolBar
{
public override void OnApplyTemplate()
{
// It is mandatory to call the base OnApplyTemplate.
base.OnApplyTemplate();
this.SetHighlightColorPallete();
}
private void SetHighlightColorPallete()
{
List<Color> colors = new List<Color>
{
Colors.Red,
Colors.Green,
Colors.Blue
};
this.HighlightColorPicker.HeaderPaletteVisibility = System.Windows.Visibility.Hidden;
this.HighlightColorPicker.StandardPaletteVisibility = System.Windows.Visibility.Hidden;
this.HighlightColorPicker.MainPaletteItemsSource = colors;
}
}
CustomSelectionMiniToolBar
element to the SelectionMiniToolBar
property of RadRichTextBox
.
Custom SelectionMiniToolBar for a .NET project
//CustomSelectionMiniToolBar attribute is not present
public class CustomSelectionMiniToolBar : SelectionMiniToolBar
{
public override void OnApplyTemplate()
{
// It is mandatory to call the base OnApplyTemplate.
base.OnApplyTemplate();
this.SetHighlightColorPallete();
}
private void SetHighlightColorPallete()
{
List<Color> colors = new List<Color>
{
Colors.Red,
Colors.Green,
Colors.Blue
};
this.HighlightColorPicker.HeaderPaletteVisibility = System.Windows.Visibility.Hidden;
this.HighlightColorPicker.StandardPaletteVisibility = System.Windows.Visibility.Hidden;
this.HighlightColorPicker.MainPaletteItemsSource = colors;
}
}
Setting the custom SelectionMiniToolBar to the RadRichTextBox control
this.richTextBox.SelectionMiniToolBar = new CustomSelectionMiniToolBar();