Adding custom object to CalendarButtonContent

3 posts, 1 answers
  1. Kasper Schou
    Kasper Schou avatar
    21 posts
    Member since:
    Jul 2009

    Posted 07 Apr 2011 Link to this post

    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. Answer
    Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 12 Apr 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kasper Schou
    Kasper Schou avatar
    21 posts
    Member since:
    Jul 2009

    Posted 15 Apr 2011 Link to this post

    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
Back to Top