How to change the Background color of a RadControl in runtime?

3 posts, 1 answers
  1. Di
    Di avatar
    16 posts
    Member since:
    Jul 2013

    Posted 05 Jul 2013 Link to this post

    I have two radcontrols:
    <telerik:RadMaskedNumericInput Name="txtC" Value="{x:Null}" IsClearButtonVisible="False" Height="30" Width="50" Mask="###" Placeholder=" " HorizontalContentAlignment="Right" HorizontalAlignment="Left" VerticalContentAlignment="Center" ValueChanged="txtC_ValueChanged" />

    and I need to know how to change the background color according to the numbers the user is going to type.
    eg: 
    if (!string.IsNullOrWhiteSpace(txtAltura.Text))
    {
       txtC.Background = "Green";
       // or
       txtC.Background = ColorNames.Green;
    }

    I already checked other solutions with System.Windows.Media.BrushConverter, but it doesn't appear in my codebehind, even using the namespace. I am using VS 2010.

    Di.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Jul 2013 Link to this post

    Hi Di,

    Please have a look at the sample C# code I tried to set the background of RadRichTextBox.

    C#:
    radRichTextBox.Background = new SolidColorBrush(Colors.Green);

    Also you can directly modify the background color of the active presenter like this:

    C#:
    ((Control)radRichTextBox.ActiveEditorPresenter).Background = new SolidColorBrush(Colors.Yellow);

    Thanks,
    Shinu.
  3. DevCraft banner
  4. Di
    Di avatar
    16 posts
    Member since:
    Jul 2013

    Posted 08 Jul 2013 Link to this post

    Thanks Shinu.
Back to Top