【发布时间】:2020-09-05 06:54:44
【问题描述】:
我有一个 Outlook vsto,它将Button 添加到所选邮件的预览窗格中。
目前 vsto 仅用于添加按钮,但其他功能即将推出。
另外我有一个 WPF Window,当点击 Button 时打开。
private void ArchiveButton_Click(object sender, EventArgs e)
{
var mail = (Outlook.MailItem)OutlookItem; // currently selected mail.
var app = new App();
app.InitializeComponent();
app.Run(new MainWindow(mail));
}
如您所见,我可以运行 App.xaml 来获取样式并将参数 mail 传递给窗口。
在这个MainWindow 中,我编辑了一些元数据并启动了存储过程,所以我需要那个 Outlook.MailItem 对象。
我找到的解决方案是有两个 MainWindow 的构造函数。一个由app.InitializeComponent() 调用,它似乎加载了样式并立即关闭,另一个由我实际使用的app.Run(new MainWindow(mail)) 调用。
public MainWindow()
{
Close();
}
public MainWindow(Outlook.MailItem mail)
{
InitializeComponent();
SearchTextBox.Text = mail == null ? "null" : "mail"; // checking if the WPF got the object
MailItem = mail;
...
}
我的问题是:
是否有更清洁/更好的解决方案来同时获取样式和参数?
【问题讨论】: