Switch To Outlook Calendar using VSTO

混江龙づ霸主 提交于 2020-01-15 10:59:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!