WPF Calendar - DisplayDate not working?

Nov 4, 2010 at 4:45 PM


I'm using the Calendar as a control in my application and I am struggling at making "DisplayDate" work.

Basically my problem is that whatever I set DisplayDate to, the Calendar will always display today's date as a default. I took .NET 4.0's example from MSDN docs just to see, and I still have the same problem, try this:

<Calendar Margin="20" 

According to this piece of code, it should display 3/15/2009. But if I run it here, Calendar is actually showing the month of April instead of March. This is because it's trying to display today's date (nov 2010) but gets blocked by "DisplayDateEnd". Remove that last property and the calendar will show Nov 2010 regardless of the DisplayDate.

Are there any workarounds to this? I am using the Feb 2010 release of the toolkit in VS2008/.NET 3.5.

Nov 4, 2010 at 8:24 PM
Edited Nov 4, 2010 at 8:24 PM

In fact, guess what? I was wrong, it works in a blank application.

But somehow, in the middle of my full application, it won't. This is what I'm using exactly:

<tk:Calendar DisplayDate="2010-01-01"/>

The actual displayed date is November 2010 in the calendar, using the line above.

The calendar is actually within a datatemplate, in a usercontrol:

<UserControl x:Class="PhaseView"

        <ResourceDictionary Source="/4 - Resources/Dictionaries/mkStyles.xaml" />

         <ListBox ItemsSource="{Binding SelectedItem.Children}">
                                    <ColumnDefinition Width="270" />
                                    <ColumnDefinition Width="*" />
                                <StackPanel Grid.Column="0">
                                    <TextBlock Text="{Binding Name}"/>
                                <TextBlock Text="{Binding Comment}" />
                                <StackPanel Orientation="Horizontal" Grid.Column="1" >
                                    <Button Command="{Binding RenameCommand}" Style="{StaticResource EditButton}" />
                                    <Button Command="{Binding DeleteCommand}" Style="{StaticResource DeleteButton}" />
                            <StackPanel Orientation="Horizontal">
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Text="From" />
                                    <tk:Calendar DisplayDate="2010-01-01"/>
                                    <TextBlock Text="{Binding PhaseStartText}" />
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Text="To" />
                                    <TextBlock Text="{Binding PhaseEndText}" />

The problem lies in <tk:Calendar> - it will always display the current month regardless of its "DisplayDate" value. Is this a bug, or something I'm doing wrong?
Also, the "mkStyles.XAML" has nothing related to calendars - it's only a collection of styles for buttons and listboxes.
Dec 3, 2010 at 10:40 PM
Edited Dec 3, 2010 at 11:06 PM

Did you find solution for this issue?  I have same problem.


If I just create a plain calendar in XAML and set DisplayDate directly with a date string, it works.  Example:

<toolkit:Calendar DisplayDate="3/1/2010" />


If I try to bind DisplayDate from within a DataTemplate, it never works.  Example:

<DataTemplate DataType="{x:Type sys:DateTime}">
     <toolkit:Calendar DisplayDate="{Binding Path=., Mode=OneWay}" />


This always shows the current month in the Calendar and it's starting to make me mad!


Using this DataTemplate, it is my goal to make ListBox full of Calendars like this:



<ListBox Padding="0" Margin="0" Background="Transparent" BorderBrush="{x:Null}" BorderThickness="0" HorizontalAlignment="Center"


To exaggerate the problem I have modified the DataTemplate like this:

<DataTemplate DataType="{x:Type sys:DateTime}">
            <StackPanel Orientation="Vertical">
                <toolkit:Calendar Background="Transparent" DisplayDate="{Binding Path=.}" />
                <TextBlock Text="{Binding Path=.}"/>

 Now, it shows the correct date in the TextBlock below the calendar.  But the Calendar will only show the current month if I try to set the DisplayDate from within the DataTemplate!  Please help!