问题
I have a CustomTaskPane that I have added to Microsoft Outlook 2013. This pane includes a WPF Calendar control that when double clicked I would like it to switch from the current Outlook view (Mail) to the Calendar view and go to the date selected in the control.
Here is the code I am using:
private void TopCalendar_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
CalendarView calView = null;
Explorer explorer;
DateTime goToDate = (TopCalendar.SelectedDate.HasValue) ? TopCalendar.SelectedDate.Value : DateTime.Today;
explorer = Globals.ThisAddIn.Application.ActiveExplorer();
Views views = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar).Views;
foreach(View v in views)
if (v.Name == "Calendar")
{
calView = (CalendarView)v;
break;
}
calView.CalendarViewMode = OlCalendarViewMode.olCalendarViewMonth;
calView.GoToDate(goToDate);
explorer.CurrentView = calView;
}
However, when I double-click on a date the code is called (verified with breakpoint) but seems to have no effect on Outlook at all. Any suggestions?
回答1:
Make sure you call Apply() to make the view the current view for the Folder
. You also need to assign the CurrentFolder to the Calendar.
calView.Apply(); // applies the view
explorer.CurrentFolder = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar); // changes current folder
来源:https://stackoverflow.com/questions/15957488/switch-to-outlook-calendar-using-vsto