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

Selection does not work.

1 Answer 59 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Sergio
Top achievements
Rank 1
Sergio asked on 30 Nov 2012, 07:29 AM
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
               xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
               <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
       {
           get
           {
               return this._dataCollection;
           }
           set
           {
               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.

1 Answer, 1 is accepted

Sort by
0
Ventzi
Telerik team
answered on 05 Dec 2012, 11:06 AM
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,
Ventzi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Calendar
Asked by
Sergio
Top achievements
Rank 1
Answers by
Ventzi
Telerik team
Share this question
or