Problem with theme on RadRadioButton with custom content

2 posts, 0 answers
  1. Jenny
    Jenny avatar
    3 posts
    Member since:
    May 2016

    Posted 12 Dec 2016 Link to this post

    We are using Telerik UI for WPF and are having some problems with the RadRadioButton when applying themes. The problem is that the style of the theme is not fully applied to the control if the content is custom, and in this case it has a stackpanel with an image and a textblock. Then the textblock won´t get the correct foreground color when selected:

           <telerik:RadRadioButton x:Name="MyRadioButton">
                <StackPanel Orientation="Horizontal">
                    <Image Width="16" Height="16" Source="../Images/icon_16x16.png"/>
                    <TextBlock>My radiobutton</TextBlock>


    When the RadRadioButton only has a text as content the styling is correct:


    <telerik:RadRadioButton x:Name="MyRadioButton" Conent="My radiobutton">


    I have tried to use RelativeSource and AncestorType in the binding but it doesn´t seem to work:

    ForeGround={Binding RelativeSource={RelativeSource AncestorType=TextBox}, Path=Tag}
  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 15 Dec 2016 Link to this post

    Hi Jenny,

    What you described as result by comparing adding direct content to the RadRadioButton and the other one with the StackPanel is expected and I'll describe why below.
    Since we don't support theming for MS TextBlock control it uses the dependency property inheritance and inherit its Foreground property from its parent in the element tree. There's very good article online that explains the property inheritance in WPF and I really recommend that you review it. So in your case the TextBlock simply inherits the Foreground property from the RadRadioButton (its logical parent).
    On the other side when you directly provide Content to the Button by using the Content property our predefined theming kicks in and since we change the ContentPresenter's  Foreground in different visual states in the RadRadioButtonStyle -- this is what you'll see as result.
    I don't really understand why are you trying to Bind to a Tag property of a TextBox element. Instead you can bind to the Foreground property of the ContentPresenter of the Button like this:

    Foreground="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter},
                   Path=(TextElement.Foreground)}" />

    I hope this information helps.

    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top