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

Adding custom object to CalendarButtonContent

2 Answers 109 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kasper Schou
Top achievements
Rank 1
Kasper Schou asked on 07 Apr 2011, 10:31 PM
Hi Telerik,

I've had a somewhat similar thread sometime ago, but here is what I need to do:

Basically what I want to achieve is to add some custom object to the CalendarButtonContent for my DataTemplate to access.

I have created a template selector and finding that the given date is a Holiday, then returning my HolidayTemplate.

public class CalendarButtonTemplateSelector : DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        CalendarButtonContent content = item as CalendarButtonContent;
        if (content != null && content.ButtonType == CalendarButtonType.Date)
        {
            if (CentralCalendarWindow.CalendarViewItems != null && CentralCalendarWindow.CalendarViewItems.Exists(c => c.Date == content.Date))
            {
                CalendarViewItem calendarViewItem = CentralCalendarWindow.CalendarViewItems.Find(c => c.Date == content.Date);
                if (calendarViewItem.IsHoliday)
                {
                    return HolidayTemplate;
                }
            }
        }
    }
}

In XAML I would like my template to achieve something like the following (where CustomText is the object somehow added to the CalendarButtonContent or otherwise referenced):

<DataTemplate>
    <StackPanel>
        <TextBlock Text="{Binding Text}" />
        <TextBlock Text="{Binding CustomText}" />
    </StackPanel>
</DataTemplate>

I would be happy if I could somehow from my template just access some custom data outside the scope of the CalendarButtonContent, i.e. some static public data, if this would somehow be possible, but I guess that has not really anything to do with your Calendar control :)

Thanks in advance!
Best regards,
Kasper Schou

2 Answers, 1 is accepted

Sort by
0
Accepted
Kaloyan
Telerik team
answered on 12 Apr 2011, 03:15 PM
Hi Kasper Schou,

Find the attached sample project It exposes a custom attached project that is using as a proxy channel between the actual template and a custom object.

Best wishes,
Kaloyan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kasper Schou
Top achievements
Rank 1
answered on 15 Apr 2011, 12:58 PM
Hi Kaloyan,

Your example has helped me create a very good implementation of my issue, narrowing it down to only a few templates and instead attaching colors and so on.

Thank you for the great support even though it was not an issue directly against your component. I'm very pleased we choose Telerik :)

Best regards,
Kasper Schou
Tags
Calendar
Asked by
Kasper Schou
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Kasper Schou
Top achievements
Rank 1
Share this question
or