Reputation: 337
i have a standard calendar control defined in my xaml file:
<Calendar Height="200" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0"
Name="NewCalendarYear" Width="200" SelectedDatesChanged="NewCalendarYear_SelectedDatesChanged" DisplayMode="Decade" />
the problem I am having is that it works properly when DisplayMode="Month", but when changing it to "Year" or "Decade" the Calendar appears empty... with one arrow pointing to the left (i am not allowed to upload images). I have been searching but I have not found a sample of any xaml calendar code that works properly in these displaymodes.
Thanks¡¡
Upvotes: 5
Views: 1493
Reputation: 13
With the previous answer and some research i have found a solution for me that works.
Unfortunately the Loaded- Event is not enough, if you like to keep the display Mode as it is set... (as microsoft tells Here ... YAY!^^)
Here is my Example Workaround in Codebehind. I have used DisplayMode "Year".
First i have assigned the Loaded- Event of the calendar control within XAML
View.xaml:
<Calendar
Loaded="Calendar_OnLoaded"
Width="auto"
DisplayDate="{x:Static sys:DateTime.Now}"
/>
Second the Codebehind Workaround
View.xaml.cs
// set Display Mode after calender is loaded for the first time and subscribe "DisplayModeChanged" Event
private void Calendar_OnLoaded(object sender, RoutedEventArgs e)
{
Calendar calObj = sender as Calendar;
calObj.DisplayMode = CalendarMode.Year;
calObj.DisplayModeChanged += new EventHandler<CalendarModeChangedEventArgs> (Calendar_DisplayModeChanged);
}
// set Display Mode each time user has made a selection within calender
private void Calendar_DisplayModeChanged(object sender,
CalendarModeChangedEventArgs e)
{
Calendar calObj = sender as Calendar;
calObj.DisplayMode = CalendarMode.Year;
}
Upvotes: 1
Reputation: 3017
I was having the same issue.
There's some kind of bug with setting the DisplayMode in XAML. If you set it in the codebehind, on the _Load event, it will work!
Upvotes: 5