Set RadRichTextBox Foreground to DynamicResource

1 Answer 46 Views
RichTextBox
Dan
Top achievements
Rank 1
Iron
Iron
Dan asked on 23 Oct 2023, 02:45 PM
Hi!
I want to be able to change themes and am setting the Background of RadRichTextBox to a DynamicResource.
That works, but when I set the Foreground to a DynamicResource the color changes only on text changed.

I want the default Foreground to change automatically.

I've attached a project 

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 26 Oct 2023, 01:29 PM

Hello Dan,

To change the foreground color of the RadRichTextBox control as desired, when merging different resource dictionaries you can call its OnApplyTemplate method.

The following code snippet shows the modified MainWindow.xaml.cs file from the sample project that you provided:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void CheckBox_Checked(object sender, RoutedEventArgs e)
    {
        var app = (App)Application.Current;

        app.ChangeTheme(true);

        this.RadRichTextBoxOnApplyTemplate();
    }

    private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
    {
        var app = (App)Application.Current;

        app.ChangeTheme(false);

        this.RadRichTextBoxOnApplyTemplate();
    }

    private void RadRichTextBoxOnApplyTemplate()
    {
        this.radRichTextBox.OnApplyTemplate();
    }
}

The produced result is as follows:

Could you give this suggestion a try?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
RichTextBox
Asked by
Dan
Top achievements
Rank 1
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or