Click on month in Silverlight Calendar in year mode, get the selected month and stay in year mode?
I want to provide a user the ability to select a month\year I was going to just use 2 listboxes but I say that the Silverlight calendar had a year mode, which displays the months of a year (not the months with all the days).
But when you click on a month it switches to displaying the days in the month selected (month mode).
I tried switching back to the year mode in the SelectedDatesChanged event. But realized that fires only after I select a specific day in a month (at which point it does switch back the the year mode).
So my questions: - can I get the calendar to stay in the year mode? - is there an event for the month selected? - can I even get the month select?
t开发者_Python百科hanks
There is a DisplayModeChanged event that can be used. I my case I needed the first date and the last date of the selected month ... the code below does what I needed.
private void CalendarDisplayModeChanged(object sender, CalendarModeChangedEventArgs e)
{
//control might be null at start up so check for null
//probably could hook up event in Loaded or constructor instead of xaml to prevent this
if (calendarInYearMode != null) {
//reset back to year mode
calendarInYearMode.DisplayMode = CalendarMode.Year;
if (calendarInYearMode.DisplayDate != DateTime.MinValue) {
var beginningOfMonthDate = calendarInYearMode.DisplayDate;
var endOfMonthDate = calendarInYearMode.DisplayDate.AddMonths(1).AddDays(-1);
}
}
}
精彩评论