Selection does not work.

2 posts, 0 answers
  1. Sergio
    Sergio avatar
    19 posts
    Member since:
    Jul 2012

    Posted 30 Nov 2012 Link to this post

    public class EventDayTemplateSelector : DataTemplateSelector
           public EventDayTemplateSelector()
               if (_eventsCollection == null)
                   _dataCollection = GenerateDayCollection.GetDateTimeCollection();
           public override DataTemplate SelectTemplate(object item, DependencyObject container)
               CalendarButtonContent content = item as CalendarButtonContent;
               foreach (DateTime d in this._dataCollection)
                   if (d == content.Date)
                       return CreateTemplate(Colors.Red);
               return base.SelectTemplate(item, container);
           private DataTemplate CreateTemplate(Color? colors)
               string color = "Black";
               string weight = "Normal";
               if (colors != null){  
                   color = colors.ToString();
                   weight = "Bold";
               if (colors == Colors.Black){
                   color = "Black";
                   weight = "Normal";
               DataTemplate dt = new DataTemplate();
               string xaml = @"<DataTemplate
                   <TextBlock FontWeight=""" + weight + @"""
                                  Foreground=""" + color + @"""
                                  Text=""{Binding Text}""/></DataTemplate>";
               return (DataTemplate)System.Windows.Markup.XamlReader.Load(xaml);

           private ObservableCollection<DateTime> _dataCollection;
           public ObservableCollection<DateTime> DataCollection
                   return this._dataCollection;
                   this._dataCollection = value;
    After assigning calendar1.DayTemplateSelector = new EventDayTemplateSelector() { DataCollection = new GenerateDayCollection()};. Stopped working on the selection of the buttons on the other day. A fine collection of data displayed in red. But the choice is not working.
  2. Ventzi
    Ventzi avatar
    114 posts

    Posted 05 Dec 2012 Link to this post

    Hello Sergio,

    Unfortunately we cannot reproduce this issue. Would you please send us working sample where we could identify this problem?

    We also noticed that on SelectTemplate method you are creating new data templates. You need to declare the data template before the selector declaration. For reference please visit our help article here.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top