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

Selectors and Special Dates

12 Answers 302 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
GG
Top achievements
Rank 1
GG asked on 24 Mar 2009, 10:47 AM
Hi,

I have a collection of DateTime and i'd like a RadCalendar with each DateTime from my collection highlited (or underlined or so...).
I have tried to follow the technics described at this url (http://www.telerik.com/help/wpf/radcalendar-selectors.html) with the DayTemplateSelector propertie.

The problem is when i'm trying this code (copy paste from the documention above) :

<telerik:RadCalendar x:Name="calendar" 
                    DayTemplate="{x:Null}" 
                    HorizontalAlignment="Center" 
                    SelectionMode="Extended" 
                    VerticalAlignment="Center"
   <telerik:RadCalendar.DayTemplateSelector> 
       <!--Custom Template selector, sill actually choose just one template--> 
       <my:CustomTemplateSelector> 
           <my:CustomTemplateSelector.DefaultTemplate> 
               <!--A custom template--> 
               <DataTemplate x:Key="defaultTemplate"
                   <TextBlock Text="{Binding Text}" /> 
               </DataTemplate> 
           </my:CustomTemplateSelector.DefaultTemplate> 
       </my:CustomTemplateSelector> 
   </telerik:RadCalendar.DayTemplateSelector> 
</telerik:RadCalendar> 

I have a compilation error saying :

The Key attribute can only be used on a tag contained in a Dictionary (such as a ResourceDictionary). (at line <DataTemplate x:Key="defaultTemplate").

When i delete the Key attribute, my software runs but each day in the RadCalendar are a DayButton.ToString() representation (i.e. Telerik.Windows.Controls.Calendar.CalendarButtonContent") and not the Day number.

Is the example in the documentation wrong ? Or i have commited a mistake.

Many Thanks in advance.

12 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 24 Mar 2009, 05:42 PM
Hello GG,

Thank you for writing us. First I want to apologize for the caused inconvenience. It appears that there is a mistake in the online help. The error you are getting is correct - it is not possible to set 'x:Key' in object which do not implement IDictionary, so you have to remove it. Also to run this example you have to remove  'DayTemplate="{x:Null}" ' in it's declaration.

Let us know if you need more assistance.

Best wishes,
Kaloyan Manev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
GG
Top achievements
Rank 1
answered on 25 Mar 2009, 08:48 AM
Hi,

Thank you for your answer. But my problem isn't resolved yet.

Indeed, I have removed the 'x:Key' and the 'DayTemplate="{x:Null}" ' in the declaration. The Calendar display now the day number at the correct format but the week-end days, like the example, are not disabled.

This my xaml code :

<telerik:RadCalendar x:Name="calendar" 
                    HorizontalAlignment="Center" 
                    SelectionMode="Extended" 
                    VerticalAlignment="Center" Grid.Row="3" Height="Auto" Grid.ColumnSpan="2" > 
            <telerik:RadCalendar.DayTemplateSelector> 
                <my:ReportingDateViewModel> 
                    <my:ReportingDateViewModel.DefaultTemplate> 
                        <DataTemplate> 
                            <TextBlock Text="{Binding Text}" Foreground="Red"/> 
                        </DataTemplate> 
                    </my:ReportingDateViewModel.DefaultTemplate> 
                </my:ReportingDateViewModel> 
            </telerik:RadCalendar.DayTemplateSelector> 
        </telerik:RadCalendar> 

and this my c# code :

using System.Windows; 
using System.Windows.Controls; 
using Telerik.Windows.Controls.Calendar; 
 
namespace WpfApplication1.ViewModel 
    public class ReportingDateViewModel : DataTemplateSelector 
    { 
        public override DataTemplate SelectTemplate(object item, DependencyObject container) 
        { 
            CalendarButtonContent content = item as CalendarButtonContent; 
            if (content != null
            { 
                if (content.Date.DayOfWeek == DayOfWeek.Saturday || content.Date.DayOfWeek == DayOfWeek.Sunday) 
                { 
                    content.IsEnabled = false
                } 
            } 
            return DefaultTemplate; 
        } 
 
        public DataTemplate DefaultTemplate 
        { 
            get
            set
        } 
    } 

It is almost the same code that in your documentation, but it doesn't work. Over more, i have tried to put a breakpoint at the begining of the SelectTemplate method but it seems to never be reached.

Where i'm wrong ?

Thanks.





0
Kaloyan
Telerik team
answered on 27 Mar 2009, 08:28 AM
Hello GG,

Once againsorry for the trouble we have caused you. After some deep investigatement, we have found that the problem is in the calendar default template. I am attaching the latest binaries where you can find the working version. Also, I am posting below the correct code:
public class ReportingDateViewModel : DataTemplateSelector 
    { 
        public override DataTemplate SelectTemplate(object item, DependencyObject container) 
        { 
            CalendarButtonContent content = item as CalendarButtonContent; 
            if (content != null
            { 
                if (content.Date.DayOfWeek == DayOfWeek.Saturday || content.Date.DayOfWeek == DayOfWeek.Sunday) 
                { 
                    content.IsEnabled = false
                } 
            } 
            return DefaultTemplate; 
        } 
 
        public DataTemplate DefaultTemplate 
        { 
            get
            set
        } 
    }  
<telerik:RadCalendar x:Name="calendar" 
            DayTemplate="{x:Null}" 
            HorizontalAlignment="Center"  
            SelectionMode="Extended"  
            VerticalAlignment="Center" Grid.Row="3" Height="Auto" Grid.ColumnSpan="2" > 
    <telerik:RadCalendar.DayTemplateSelector> 
        <my:ReportingDateViewModel> 
            <my:ReportingDateViewModel.DefaultTemplate> 
                <DataTemplate> 
                    <TextBlock Text="{Binding Text}" /> 
                </DataTemplate> 
            </my:ReportingDateViewModel.DefaultTemplate> 
        </my:ReportingDateViewModel> 
    </telerik:RadCalendar.DayTemplateSelector> 
</telerik:RadCalendar> 

Hope this helps.

Kind regards,
Kaloyan Manev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
GG
Top achievements
Rank 1
answered on 27 Mar 2009, 09:51 AM
Hi,

Thank you for your answer.

But i doesnt find the latest binary attached to your post.

Did you forget it ?

Again thank you for your support.

Best regards.
G. Moelens.
0
dloeffler
Top achievements
Rank 1
answered on 27 Mar 2009, 01:20 PM
Hi,

we have currently the same problems. Look at the Demo under Calendar -> Selection Range and Constraints. The second calendar should show disable weekend days. But it doesn't. So I think the DaySelectorTemplate does currently nothing

Regards,

Dany
0
Accepted
Kaloyan
Telerik team
answered on 30 Mar 2009, 11:55 AM
Hi Dany,

Thanks for your report.

We are aware of the problem and we have already addressed it. The fix will be included in the forthcoming SP1 release due in two weeks. I am also attaching the latest trial binaries.

Regards,
Kaloyan Manev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Cole Larson
Top achievements
Rank 1
answered on 10 Dec 2009, 04:40 PM
FYI;

When I run your Demo I notice that on the Demo Calendars that disallow weekend selection, the first Saturday of every month is selected erroneously  when you do a multidate selection that includes it..   I am running Windows 7 x64

I downloaded the Demo yesterday...

Best wishes.

0
Kaloyan
Telerik team
answered on 14 Dec 2009, 09:37 AM
Hello Cole Larson,

Thank you for providing us with this information. Actually this is a bug in the control implementation. We will try to fix it for the next release.

Best wishes,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Michael
Top achievements
Rank 1
answered on 17 Mar 2010, 04:40 AM
What about if we like to pass the parameter to ReportingDateViewModel Selector? 

Let's say we are creating HighLightPublicHolidaySelector and we need to pass the list of holidays that we define in database... 

Using the attached property in Selector has a few problem as well. http://stackoverflow.com/questions/2456262/pass-data-to-data-template-selector
0
Michael
Top achievements
Rank 1
answered on 17 Mar 2010, 10:12 AM
Using the attached property and static variable solved the problem but using static variable for this case is not good solution. 
0
Kaloyan
Telerik team
answered on 19 Mar 2010, 10:36 AM
Hi Michael,

You can set a ViewModel that will hold the needed dates. In the ReportingDateVieModel you can obtain a reference to the RadCalendar using the following code:
public class ReportingDateViewModel : DataTemplateSelector 
    
        CustomViewModel viewModel; 
    
        public override DataTemplate SelectTemplate(object item, DependencyObject container) 
        
            if (viewModel == null
            
                var calendar = (container as FrameworkElement).ParentOfType<RadCalendar>(); 
                if (calendar != null
                
                    viewModel = calendar.DataContext as CustomViewModel; 
                
            
    
            var content = item as CalendarButtonContent; 
    
            if (content != null
            
                if (content.Date.DayOfWeek == DayOfWeek.Saturday || content.Date.DayOfWeek == DayOfWeek.Sunday) 
                
                    content.IsEnabled = false
                
            
            return DefaultTemplate; 
        
    
        public DataTemplate DefaultTemplate 
        
            get
            set
        
    }

Regards,
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
Michael
Top achievements
Rank 1
answered on 29 Mar 2010, 07:51 AM
Thanks.. 
Tags
Calendar
Asked by
GG
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
GG
Top achievements
Rank 1
dloeffler
Top achievements
Rank 1
Cole Larson
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or