Add Button to RadScheduleView's Day Header

1 Answer 76 Views
ScheduleView
Chris
Top achievements
Rank 1
Iron
Chris asked on 14 Dec 2021, 03:30 AM

Hi,

I've got a simple RadScheduleView which is displayed as a Week view only. I want to add a button to the Day Header which provides some custom "Lock" logic for that day. However, no matter what I do, the button in the header is always disabled.

Is there any way that I can achieve this?

My code:

<telerik:RadScheduleView AppointmentsSource="{Binding Items}">
    <telerik:RadScheduleView.GroupHeaderContentTemplate>
        <DataTemplate>
            <Grid>
                <TextBlock Text="{Binding Name, StringFormat=dd dddd}" HorizontalAlignment="Center" VerticalAlignment="Center"/
                <Button Content="🔓" HorizontalAlignment="Right" IsEnabled="True" />
            </Grid>
        </DataTemplate>
    </telerik:RadScheduleView.GroupHeaderContentTemplate>
    <telerik:RadScheduleView.ViewDefinitions>
        <telerik:WeekViewDefinition  />
    </telerik:RadScheduleView.ViewDefinitions>
</telerik:RadScheduleView>
Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 16 Dec 2021, 02:30 PM

Hello Chris,

This behavior is expected because there isn't a DayViewDefinition present in the ViewDefinitions collection of the RadScheduleView control. The custom button from the provided GroupHeaderContentTemplate template is placed inside a GroupHeaderButton button, which opens the DayViewDefinition with the current day. When there isn't a day view definition, the attached command to the GroupHeaderButton disables it. 

With that said, you could still achieve the wanted behavior by manually removing the command for every GroupHeaderButton instance. For example, you could do this in the Loaded event handler of the RadScheduleView control, and via the ChildrenOfType extension method, to get every button of type GroupHeaderButton. Then, cast the current button's DataContext property to GroupHeaderProxy class, and if the Name property is of type DateTime, set the Command and the CommandParameter property to null, and clear the CommandBindings collection.

The following code snippet has the above-mentioned logic implemented in the Loaded event of the ScheduleView control:

private void RadScheduleView_Loaded(object sender, RoutedEventArgs e)
{
    var groupHeaderButtons = this.scheduleView.ChildrenOfType<GroupHeaderButton>();
    foreach (var button in groupHeaderButtons)
    {
        var proxy = button.DataContext as GroupHeaderProxy;
        if (proxy.Name is DateTime)
        {
            button.Command = null;
            button.CommandBindings.Clear();
            button.CommandParameter = null;
        }
    }
}

I have attached a sample project that has this logic implemented, so, could you give it a try and let me know how it goes?

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ScheduleView
Asked by
Chris
Top achievements
Rank 1
Iron
Answers by
Stenly
Telerik team
Share this question
or