使用VSTO切换到Outlook日历 [英] Switch To Outlook Calendar using VSTO

查看:113
本文介绍了使用VSTO切换到Outlook日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已添加到Microsoft Outlook 2013的CustomTaskPane.此窗格包括WPF日历控件,双击该控件时,我希望它从当前的Outlook视图(邮件)切换到日历视图并转到日期在控件中选择.

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;
}

但是,当我双击一个日期时,该代码被调用(用断点验证),但似乎对Outlook完全没有影响.有什么建议吗?

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?

推荐答案

请确保您致电 Apply() ,以使该视图成为Folder的当前视图.您还需要将 CurrentFolder 分配给日历.

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

这篇关于使用VSTO切换到Outlook日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆