gpt4 book ai didi

wpf - 在 Outlook 中显示 WPF 窗口时的奇怪行为

转载 作者:行者123 更新时间:2023-12-04 21:43:46 29 4
gpt4 key购买 nike

我使用以下代码从 Outlook 中的新消息窗口显示我的 WPF 窗口:

private void DisplayWindow(Window window) {
var wih = new System.Windows.Interop.WindowInteropHelper(window);
wih.Owner = GetForegroundWindow();
window.ShowInTaskbar = false;
window.ShowDialog();
}

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

我的问题是,当 ToolTips 和 ComboBox 下拉菜单变为可见时,WPF 窗口消失在新消息窗口后面,只留下前面的“弹出”内容。谁能解释为什么会发生这种情况,以及托管窗口的正确方法是什么?

编辑:

这只发生在将收件人添加到“发送”框中后,并且似乎只有在前台窗口是新邮件消息窗口时才会出现问题。

复制:

将 Outlook 加载项项目和 WPF 项目(面向 .NET 4.0)添加到新解决方案。

在 MainWindow.xaml 上放置一个包含几个项目的 ComboBox。

删除 StartupUri从 App.xaml 并将以下内容添加到 App.cs。
public void ShowWindow() {
MainWindow window = new MainWindow();
var wih = new System.Windows.Interop.WindowInteropHelper(window);
wih.Owner = GetForegroundWindow();
window.ShowInTaskbar = false;
window.ShowDialog();
}

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

添加对 WindowsBase 的引用, System.XamlPresentationFramework到 Outlook 项目。

使用 .xml 中的以下内容将功能区 (XML) 添加到 Outlook 项目。
<customUI ...>
<ribbon>
<tabs>
<tab idMso="TabNewMailMessage">
<group id="MyGroup"
insertAfterMso="GroupMailNew">
<button id="myButton"
size="large"
onAction="myButton_Action"
imageMso="HappyFace"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

将以下内容添加到功能区代码中。
MyWpfApplication.App app;

public void Ribbon_Load(Office.IRibbonUI ribbonUI) {
this.ribbon = ribbonUI;

var appThread = new Thread(new ThreadStart(() => {
this.app = new MyWpfApplication.App();
app.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
app.Run();
}));
appThread.SetApartmentState(ApartmentState.STA);
appThread.Start();
}

public void myButton_Action(Office.IRibbonControl control) {

// Dispatcher used as cross thread operation.
app.Dispatcher.BeginInvoke((Action)(() => {
app.ShowWindow();
}));
}

将以下内容添加到 ThisAddIn
protected override Microsoft.Office.Core
.IRibbonExtensibility CreateRibbonExtensibilityObject() {
return new Ribbon();
}

运行 Outlook 加载项,创建新邮件, 添加收件人 然后单击笑脸按钮。当您单击 ComboBox 时,您将看到该错误。 .

最佳答案

也许您遇到了臭名昭著的“空域”问题。见 here , herehere .人们对它在 .NET 4.5 中得到修复寄予厚望,但遗憾的是,当 MS 宣布修复本身有太多问题无法发布时,这些愿望落空了。

关于wpf - 在 Outlook 中显示 WPF 窗口时的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14436776/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com