Styling RadComboBox

3 posts, 1 answers
  1. Ken Jones
    Ken Jones avatar
    41 posts
    Member since:
    Sep 2009

    Posted 20 Dec 2011 Link to this post

    Hello,

    This should be a fairly simple thing but I have searched the forums and others seem to be having similar issues and I havent been able to apply the solutions from any of the other posts.

    I would like to apply a red border to the RadComboBox when a button is pressed, this is acheived simply for a standard silverlight ComboBox by the following:

    App.xaml:
    <Style TargetType="ComboBox" x:Key="RedBorderComboBox">
        <Setter Property="BorderBrush" Value="Red" />
        <Setter Property="BorderThickness" Value="1" />
    </Style>

    Page.xaml.cs:
    Style redBorderStyleComboBox = Application.Current.Resources["RedBorderComboBox"] as Style;
     
    var cb = control as ComboBox;
    if (cb.SelectedValue == null)
    {
        cb.Style = redBorderStyleComboBox;
    }

    Please can someone explain how to acheive this with a RadComboBox?

    Thanks,
    Ken
  2. Answer
    Dani
    Admin
    Dani avatar
    848 posts

    Posted 21 Dec 2011 Link to this post

    Hello Ken,

    If you apply a Style to RadComboBox dynamically, you will have to recreate the control so it can pick up the new style. Otherwise, your Style will not get applied.

    Instead, you can simply try setting the BorderBrush property to Red:
    if (this.cb.SelectedValue == null)
                {
                    this.cb.BorderBrush = new SolidColorBrush(Colors.Red);
                }

    But still, it depends when exactly you wish draw a red border around the control. If you are doing any kind of data validation, you can use the Validation visual states of RadComboBox for your customization. By default RadComboBox does include a ValidationToolTip, which you can see demonstrated in the Data Validation online example.

    I hope this helps.

    Regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Ken Jones
    Ken Jones avatar
    41 posts
    Member since:
    Sep 2009

    Posted 21 Dec 2011 Link to this post

    Thanks for your feedback, I like the validation example but to remain consistent I will go with your other approach which works well.

    Cheers,

    Ken
Back to Top