Custom color to the HeaderBackground property

5 posts, 1 answers
  1. Birgit
    Birgit avatar
    19 posts
    Member since:
    Apr 2016

    Posted 13 Jul Link to this post

    Hello

     

    how can I set custom color to the HeaderBackground property of the RadLayoutControl (LayoutControlExpanderGroup)?

    I tried similar way for setting implicit styles mechanism like setting the HeaderBackground of RadLayoutControl, but this not work:

    <Style TargetType="telerik:RadLayoutControl" BasedOn="{StaticResource RadLayoutControlStyle}">
        <Setter Property="HeaderBackground" Value="Yellow" />
    </Style>

     

    It can not be difficult, but I do not find anything in the documentation.

    Thanks for any help.

    Birgit

  2. Dinko
    Admin
    Dinko avatar
    416 posts

    Posted 17 Jul Link to this post

    Hi Birgit,

    Thank you for your interest in RadLayoutControl

    LayoutControl doesn't expose such property. In your case, you want to change the style of the LayoutControlExpanderGroup. To do this you can extract and edit the default template of the control. You can take a look at the Editing Control Templates help article which describes how to extract the default template. 

    In your case, in the extracted template you can navigate to the Style (TargetType="{x:Type telerik:RadToggleButton}") set to the HeaderButtonStyle property of the RadExpander and change the Background property. I have prepared a sample project which demonstrates this approach. Can you give this project a try and let me know if it works for your scenario.

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Birgit
    Birgit avatar
    19 posts
    Member since:
    Apr 2016

    Posted 17 Jul in reply to Dinko Link to this post

    Hello Dinko

    many thanks for your answer and your example. It works good, but I am very surprised - I have to overwrite the entire style just to change the color? This solution has problems with future Telerik updates, right? I'm not sure, but I think I've then always an 'old' LayoutControlExpanderGroup...or not?

     

    Kind regards

    Birgit

     

    Kind regards

    Birgit

  4. Answer
    Dinko
    Admin
    Dinko avatar
    416 posts

    Posted 20 Jul Link to this post

    Hello Birgit,

    You are right. Basically, every new release you need to download the latest version and extract the template again in order to have up to date template. 

    What I could suggest you is to use ChildrenOfType<T>() extension method. You can subscribe to the Loaded event of the RadLayoutControl. In the event handler, using this method you can search in the visual tree of the expander group in order to get the RadToggleButton control and change its Background property. Using this approach you don't have to worry about the new version of our controls.
    public MainWindow()
    {
        InitializeComponent();
        this.myLayoutControl.Loaded += MyLayoutControl_Loaded;
    }
     
    private void MyLayoutControl_Loaded(object sender, RoutedEventArgs e)
    {
        var toggleButton = this.myExpanderGroup.ChildrenOfType<RadToggleButton>().FirstOrDefault();
        if (toggleButton != null)
        {
            toggleButton.Background = new SolidColorBrush(Colors.Purple);
        }
    }

    I have logged a feature request in our Feedback Portal for creating a property in order to customize the header of the LayoutControlExpanderGroup.

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Birgit
    Birgit avatar
    19 posts
    Member since:
    Apr 2016

    Posted 20 Jul Link to this post

    Hi Dinko

    thank you for the feature request.

    I like your proposal, so I'll use the ChildrenOfType<T>() extension method.

    Thank you very much

    Birgit

Back to Top