This is a migrated thread and some comments may be shown as answers.

GroupHeaderContentTemplateSelector

1 Answer 93 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 11 Jan 2013, 04:17 PM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 16 Jan 2013, 12:31 PM
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.

Tags
ScheduleView
Asked by
Tim
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or