Selectors and Special Dates

13 posts, 1 answers
  1. GG
    GG avatar
    7 posts
    Member since:
    Mar 2009

    Posted 24 Mar 2009 Link to this post

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

    Posted 24 Mar 2009 Link to this post

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

    Posted 25 Mar 2009 Link to this post

    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.





  5. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 27 Mar 2009 Link to this post

    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.
  6. GG
    GG avatar
    7 posts
    Member since:
    Mar 2009

    Posted 27 Mar 2009 Link to this post

    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.
  7. dloeffler
    dloeffler avatar
    3 posts
    Member since:
    Mar 2009

    Posted 27 Mar 2009 Link to this post

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

    Posted 30 Mar 2009 Link to this post

    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.
  9. Cole Larson
    Cole Larson avatar
    1 posts
    Member since:
    Dec 2009

    Posted 10 Dec 2009 Link to this post

    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.

  10. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 14 Dec 2009 Link to this post

    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.
  11. Michael
    Michael avatar
    22 posts
    Member since:
    Aug 2008

    Posted 16 Mar 2010 Link to this post

    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
  12. Michael
    Michael avatar
    22 posts
    Member since:
    Aug 2008

    Posted 17 Mar 2010 Link to this post

    Using the attached property and static variable solved the problem but using static variable for this case is not good solution. 
  13. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 19 Mar 2010 Link to this post

    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.
  14. Michael
    Michael avatar
    22 posts
    Member since:
    Aug 2008

    Posted 29 Mar 2010 Link to this post

    Thanks.. 
Back to Top
UI for WPF is Visual Studio 2017 Ready