Hi Petar,
i am using below code in my project.
=====================================================================================================
XAML file code
<Window x:Class="ColorPickerAutomaticIssue.MainWindow"
Title="MainWindow" xmlns:tel="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls"
xmlns:telerikRibbonBar="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.RibbonBar"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" ></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<telerikRibbonBar:RadOrderedWrapPanel VerticalAlignment="Top">
<telerikRibbonBar:RadButtonGroup>
<telerikRibbonBar:RadRibbonButton Text="Font Color" telerikRibbonBar:ScreenTip.Title="Font Color" telerikRibbonBar:ScreenTip.Description="Change the text color.">
<tel1:RadColorPicker Name="rbcolor" MainPalette="Civic" HeaderPalette="Civic" Click="foregroundColor_click" DropDownOpened="fontColor_DropDownOpened"/>
</telerikRibbonBar:RadRibbonButton>
</telerikRibbonBar:RadButtonGroup>
</telerikRibbonBar:RadOrderedWrapPanel>
<RichTextBox Name="mainRichTextBox" Grid.Row="1" AcceptsTab="True" AcceptsReturn="True" dragDrop:RadDragAndDropManager.AllowDrop="True"
VerticalScrollBarVisibility="Auto" SpellCheck.IsEnabled="True" Focusable="True"
Background="White" Margin="2,0,0,5" KeyDown="mainRichTextBox_KeyDown"
TabIndex="0" ForceCursor="True" IsUndoEnabled="True" IsDocumentEnabled="True" Loaded="mainRichTextBox_Loaded" SelectionChanged="mainRichTextBox_SelectionChanged" >
</RichTextBox>
</Grid>
</Window>
========================================================================================================
CS File Code
using Telerik.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace ColorPickerAutomaticIssue
{
public partial class MainWindow : Window
{
private int updatingUI = 0;
public MainWindow()
{
InitializeComponent();
}
private void mainRichTextBox_KeyDown(object sender, KeyEventArgs e)
{
TextRange range = new TextRange(mainRichTextBox.Selection.Start, mainRichTextBox.Selection.End);
updatingUI = 0;
}
private void mainRichTextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
TextRange selectionRange = new TextRange(mainRichTextBox.Selection.Start, mainRichTextBox.Selection.End);
TextPointer tp = mainRichTextBox.CaretPosition.GetInsertionPosition(LogicalDirection.Forward);
TextRange tr = new TextRange(tp, tp);
Run r = new Run(tr.Text);
tr.ApplyPropertyValue(FlowDocument.FontFamilyProperty, "Arial");
mainRichTextBox.Focus();
}
private void mainRichTextBox_Loaded(object sender, RoutedEventArgs e)
{
TextRange range = new TextRange(mainRichTextBox.Selection.Start, mainRichTextBox.Selection.End);
range.ApplyPropertyValue(RichTextBox.FontFamilyProperty, "Arial");
}
private void fontColor_DropDownOpened(object sender, EventArgs e)
{
Popup popup = this.rbcolor.ChildrenOfType<Popup>()[0];
RadColorSelector Radselector1 = VisualTreeHelper.GetChild(popup.Child, 0) as RadColorSelector;
Radselector1.AddHandler(RadColorPaletteViewItem.MouseLeftButtonDownEvent, new System.Windows.Input.MouseButtonEventHandler(this.FontColorSelectorItemMouseClick), true);
Radselector1.AddHandler(RadColorPaletteViewItem.MouseMoveEvent, new System.Windows.Input.MouseEventHandler(this.FontColorSelectorItemMouseMove), true);
}
private void FontColorSelectorItemMouseMove(object sender, MouseEventArgs e)
{
if (e.OriginalSource.GetType().FullName.Equals("System.Windows.Shapes.Rectangle"))
{
if (mainRichTextBox != null)
{
if (updatingUI == 1)
return;
TextRange range = mainRichTextBox.Selection;
range.ApplyPropertyValue(TextElement.ForegroundProperty,new SolidColorBrush((Color)ColorConverter.ConvertFromString(((System.Windows.Shapes.Shape)(e.OriginalSource)).Fill.ToString())));
}
}
}
private void FontColorSelectorItemMouseClick(object sender, MouseButtonEventArgs e)
{
if (mainRichTextBox != null)
{
if (updatingUI == 1)
return;
TextRange range = mainRichTextBox.Selection;
range.ApplyPropertyValue(TextElement.ForegroundProperty,
new SolidColorBrush((sender as RadColorSelector).SelectedColor));
mainRichTextBox.Focus();
}
}
private void foregroundColor_click(object sender, EventArgs e)
{
if (mainRichTextBox != null)
{
if (updatingUI == 1)
return;
TextRange range = mainRichTextBox.Selection;
range.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush((sender as RadColorPicker).SelectedColor));
mainRichTextBox.Focus();
}
}
}
}