RadButton content foreground not always correct with Office 2016 theme

5 posts, 0 answers
  1. Moyle
    Moyle avatar
    12 posts
    Member since:
    Jul 2017

    Posted 18 Dec 2018 Link to this post

    Hi,

    I noticed that the Office 2016 theme is the only theme where the RadButton foreground and background colors get inverted on mouse hover.

    Unfortunately, if I do this, the text stays black even on mouse hover:

    <telerik:RadButton>
        <TextBlock Text="Test" />
    </telerik:RadButton>

     

    The following 2 versions work:

    <telerik:RadButton Content="Test" />

    <telerik:RadButton>
        <telerik:RadButton.ContentTemplate>
            <DataTemplate>
                <TextBlock Text="Test" />
            </DataTemplate>
        </telerik:RadButton.ContentTemplate>
    </telerik:RadButton>

     

    But I cannot use the first because in reality the content I want to put in the button is more complex (TextBlock containing Run objects).
    And the second would be a workaround which I would like to avoid as it is not the optimal way.

    The reason it does not work is because the IsMouseOver trigger in the template does this:

    <Setter TargetName="Content" Property="TextElement.Foreground" Value="{telerik1:Office2016Resource ResourceKey=MarkerInvertedBrush}"/>

     

    By setting TextElement.Foreground on the ContentPresenter inside the control's template, only children that consider the ContentPresenter as their logical parent will inherit from its Foreground property.

    • When using the ContentTemplate property, the elements within the DataTemplate become logicial descendents of the ContentPresenter, so the inheritence of the Foreground property works.
    • When using the Content property, the logical parent of the topmost element that forms the content is not the ContentPresenter within the control's template, but the control (RadButton) itself. Therefore the foreground of the content will depend on the Foreground property of the control itself. The latter is not changed by the trigger, so it stays black, and so does the content's foreground.

    The seemingly obvious fix would be to change the template trigger's setter to this:

    <Setter Property="Foreground" Value="{telerik1:Office2016Resource ResourceKey=MarkerInvertedBrush}"/>

     

    If you feel like this is an appropriate fix, please include it in future versions so that we do not have to customize your template just for that.
    If not, and you have advice, you're welcome share it.

    Best regards

  2. Moyle
    Moyle avatar
    12 posts
    Member since:
    Jul 2017

    Posted 18 Dec 2018 in reply to Moyle Link to this post

    You might also want to adjust the Setter inside the trigger for IsPressed the same way.

    Another thing to look into, is the following attribute on the ContentPresenter:

    TextBlock.Foreground="{TemplateBinding Foreground}"

    Is it really needed? And if so, why specifically TextBlock? TextBlock.Foreground seems to be an alias for TextElement.Foreground.

    Here is a sample project: https://we.tl/t-nCAkCBWjir
    You might need to adjust the NuGet package reference, which was for our internal NuGet repository

  3. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    934 posts

    Posted 21 Dec 2018 Link to this post

    Hi Moyle,

    Thank you very much for your feedback.

    Indeed, all three remarks seem like oversights at our end, the fix to which I've already applied in our source code and, once it passes our testing process, it should be available with our next official release which will be introduced in the middle of January. I do hope you find such a time frame suitable and are satisfied with the current workaround you've applied.

    As a thank you for your help in addressing this issue, I've awarded you with some Telerik points.

    Please let me know if any other questions or concerns arise or if I can further assist you in any way.

    Regards,
    Dilyan Traykov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  4. Moyle
    Moyle avatar
    12 posts
    Member since:
    Jul 2017

    Posted 18 Jan in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

    Thanks for the quick support.
    Unfortunately I won't be able to test on the newer releases soon, as we don't change the Telerik version very often.
    I guess I'll find out when our organization decides to upgrade to a newer release.
    In the meantime we just apply a fixed control template as workaround.

    Regards

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    934 posts

    Posted 18 Jan Link to this post

    Hi Moyle,

    I do hope you find the workaround suitable for the time being.

    What I can suggest is to wait for the release of our upcoming service pack in the middle of February and update to that version of the controls if you find it possible.

    In the meantime, feel free to contact me if any other questions or concerns arise.

    Regards,
    Dilyan Traykov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top