GroupHeaderContentTemplateSelector

2 posts, 1 answers
  1. Tim
    Tim avatar
    41 posts
    Member since:
    Oct 2012

    Posted 11 Jan 2013 Link to this post

    I have GroupHeaderContentTemplateSelector working for my control. I am currently showing null groups as well.

    My template basically colors in the background of the resource to black and sets the font to white. However, the empty group that appears does not take on this template.

    1) How can I apply the template to the null group?
    2) How can I place custom text in as the header for the null group?

    Thanks,

    Tim
  2. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 16 Jan 2013 Link to this post

    Hello Tim,

    I would suggest to create a custom GroupHeaderContentTemplateSelector as explained here and add a DataTemplate for the NullGroups:

    public class CustomGroupHeaderContentTemplateSelector : ScheduleViewDataTemplateSelector
    {
        public DataTemplate HorizontalTemplate { set; get; }
        public DataTemplate VerticalTemplate { set; get; }
        public DataTemplate NullGroupTemplate { set; get; }
             
        public override DataTemplate SelectTemplate(object item, DependencyObject container, ViewDefinitionBase activeViewDeifinition)
        {
            CollectionViewGroup cvg = item as CollectionViewGroup;
     
            if (cvg != null)
            {
                if (cvg.Name == null)
                {
                    return this.NullGroupTemplate;
     
                }
                if (activeViewDeifinition.GetOrientation() == Orientation.Vertical)
                {
                    return this.HorizontalTemplate;
                }
                else
                {
                    return this.VerticalTemplate;
                }
            }
            return base.SelectTemplate(item, container, activeViewDeifinition);
        }
    }

    and in XAML:

    <example:CustomGroupHeaderContentTemplateSelector x:Key="CustomGroupHeaderContentTemplateSelector">
        <example:CustomGroupHeaderContentTemplateSelector.HorizontalTemplate>
            <DataTemplate>
                <Border Background="Red">
                    <ContentPresenter Content="{Binding FormattedName}" Height="16" Margin="4" />
                </Border>
            </DataTemplate>
        </example:CustomGroupHeaderContentTemplateSelector.HorizontalTemplate>
        <example:CustomGroupHeaderContentTemplateSelector.VerticalTemplate>
            <DataTemplate>
                <telerikPrimitives:LayoutTransformControl VerticalAlignment="Top">
                    <telerikPrimitives:LayoutTransformControl.LayoutTransform>
                        <RotateTransform Angle="-90" />
                    </telerikPrimitives:LayoutTransformControl.LayoutTransform>
                    <ContentPresenter Content="{Binding FormattedName}" Margin="4" Height="16" />
                </telerikPrimitives:LayoutTransformControl>
            </DataTemplate>
        </example:CustomGroupHeaderContentTemplateSelector.VerticalTemplate>
        <example:CustomGroupHeaderContentTemplateSelector.NullGroupTemplate>
            <DataTemplate>
                <Border Background="Red">
                    <TextBlock Text="Without resource" Height="16" Margin="4" />
                </Border>
            </DataTemplate>
        </example:CustomGroupHeaderContentTemplateSelector.NullGroupTemplate>
    </example:CustomGroupHeaderContentTemplateSelector>

    Hope this helps.

    All the best,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top