Calendar converts to Day view from Year view after selecting a date
-
Tuesday, February 28, 2012 9:51 PM
I'm creating a calendar as such
private void btnDateOfData_Click(object sender, RoutedEventArgs e) { Calendar cldrDateOfDate = new Calendar(); cldrDateOfDate.Height = 170; cldrDateOfDate.HorizontalAlignment = HorizontalAlignment.Left; cldrDateOfDate.Margin = new Thickness(101, 31, 0, 0); cldrDateOfDate.Name = "cldrDateOfData"; cldrDateOfDate.VerticalAlignment = VerticalAlignment.Top; cldrDateOfDate.Width = 180; cldrDateOfDate.Visibility = System.Windows.Visibility.Visible; cldrDateOfDate.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs>(cldrDateOfDate_SelectedDatesChanged); cldrDateOfDate.Loaded += new RoutedEventHandler(cldrDateOfDate_Loaded); grdForm.Children.Add(cldrDateOfDate); } void cldrDateOfDate_Loaded(object sender, RoutedEventArgs e) { ((Calendar)sender).DisplayMode = CalendarMode.Year; } void cldrDateOfDate_SelectedDatesChanged(object sender, SelectionChangedEventArgs e) { string tempdate = ((Calendar)sender).SelectedDate.ToString(); tempJobItem.DateOfData = tempdate; ((FrameworkElement)sender).Visibility = System.Windows.Visibility.Hidden; }and after I run thebtnDateOfData_Click event, my calender has a displaymode of year, but after I select a date, the displaymode switches to day. It should just become hidden.
- Edited by Newmanb1 Tuesday, February 28, 2012 9:52 PM
All Replies
-
Wednesday, February 29, 2012 8:30 AMModerator
Hi Newmanb1,
Use DisplayDateChanged event instead.
Set a break point at the line of SelectedDatesChanged event, you will find this event does not fire until select a date in day mode.
Have a nice day,
Kee Poppy [MSFT]
MSDN Community Support | Feedback to us
-
Wednesday, February 29, 2012 8:44 AM
Hi NewMan
I got the Solution for your problem hear is the code
private void Button_Click(object sender, RoutedEventArgs e) { Calendar cldrDateOfDate = new Calendar(); cldrDateOfDate.Height = 170; cldrDateOfDate.HorizontalAlignment = HorizontalAlignment.Left; cldrDateOfDate.Margin = new Thickness(101, 31, 0, 0); cldrDateOfDate.Name = "cldrDateOfData"; cldrDateOfDate.VerticalAlignment = VerticalAlignment.Top; cldrDateOfDate.Width = 180; cldrDateOfDate.Visibility = System.Windows.Visibility.Visible; cldrDateOfDate.Loaded += new RoutedEventHandler(cldrDateOfDate_Loaded); cldrDateOfDate.DisplayDateChanged += new EventHandler<CalendarDateChangedEventArgs>(cldrDateOfDate_DisplayDateChanged); _mainDockPanel.Children.Add(cldrDateOfDate); } void cldrDateOfDate_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e) { var calendar = sender as Calendar; string tempdate = new DateTime(calendar.DisplayDate.Year, calendar.DisplayDate.Month, 1).ToString(); tempJobItem.DateOfData = tempdate; ((FrameworkElement)sender).Visibility = System.Windows.Visibility.Hidden; } void cldrDateOfDate_Loaded(object sender, RoutedEventArgs e) { ((Calendar)sender).DisplayMode = CalendarMode.Year; }
here your date will be the first date of the month you select
and i think this is good question and i was thinking of creating this but i don't get time for that
thanks for your question i again remember that
i think This is working as your descripton
Thanks
Mayank
- Marked As Answer by Newmanb1 Wednesday, February 29, 2012 6:10 PM

