从 VSTO Outlook 加载项生成的居中 WPF 对话框

发布于 2025-01-07 19:55:52 字数 869 浏览 5 评论 0原文

我正在开发一个 Outlook 2010 加载项,它提供了一个用于用户输入的对话框。在功能区中显示按钮所需的代码位于其自己的 Outlook 2010 加载项项目中。该项目引用了负责大部分工作的 WPF 用户控件库。

我在 WPF 用户控件库项目中使用静态方法,该方法负责正确配置 Caliburn.Micro 并显示对话框。所有这些都按预期工作,只是我无法弄清楚如何正确定位对话框。我希望它显示在 Outlook 窗口的中央。我知道我可以访问 Microsoft.Office.Interop.Outlook.Application.ActiveWindow(),但我不知道这对我有何帮助,因为我无法将其转换为 PlacementTarget code> 正如 Caliburn.Micro WindowManager 的 ShowDialog 方法的设置中所预期的那样。

WPF 用户控件库

namespace WpfUserControlLibrary {
    public static class Connector {
        public static void ShowDialog() {
            new AppBootstrapper();
            var windowManager = IoC.Get<IWindowManager>();
            windowManager.ShowDialog( new ShellViewModel() );
        }
    }
}

Outlook 2010 加载项

WpfUserControlLibrary.Connector.ShowDialog();

I'm working on an Outlook 2010 add-in that provides a dialog for user input. The code necessary for displaying the button in the ribbon is in its own Outlook 2010 Add-in project. That project has a reference to a WPF User Control Library that is responsible for the bulk of the work.

I use a static method in the WPF User Control Library project that is responsible for configuring Caliburn.Micro correctly and displaying the dialog. All of this works as expected except that I cannot figure out how to correctly position the dialog. I would like it to display centered over the Outlook window. I know I have access to the Microsoft.Office.Interop.Outlook.Application.ActiveWindow(), but I do not see how that helps me since I cannot translate it to a PlacementTarget as expected in the settings for Caliburn.Micro WindowManager's ShowDialog method.

WPF User Control Library

namespace WpfUserControlLibrary {
    public static class Connector {
        public static void ShowDialog() {
            new AppBootstrapper();
            var windowManager = IoC.Get<IWindowManager>();
            windowManager.ShowDialog( new ShellViewModel() );
        }
    }
}

Outlook 2010 Add-in

WpfUserControlLibrary.Connector.ShowDialog();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2025-01-14 19:55:52

我能够找到解决方案。感谢这个问题的帮助,我能够将适当的父窗口位置和大小参数传递给连接器。我检查了 Caliburn.Micro 源代码,发现我实际上正在创建一个 ChildWindow,而不是 Popup。因此,我只需要设置对话框设置的 TopLeft 值。

WPF 用户控件库

namespace WpfUserControlLibrary {
    public static class Connector {
        public static void ShowDialog(System.Windows.Rect parent) {
            new AppBootstrapper();
            var windowManager = IoC.Get<IWindowManager>();

            // Popup is always 600 x 400
            dynamic settings = new System.Dynamic.ExpandoObject();
            settings.Left = (parent.Left + parent.Width / 2) - 300;
            settings.Top = (parent.Top + parent.Height / 2) - 200;

            windowManager.ShowDialog(new ShellViewModel(), settings: settings);
        }
    }
}

Outlook 2010 加载项

var win = ThisAddIn.Application.ActiveWindow();
var parent = new System.Windows.Rect(win.Left, win.Top, win.Width, win.Height);
WpfUserControlLibrary.Connector.ShowDialog(parent);

I was able to track down a solution. Thanks to the help of this question, I was able to pass the appropriate parent window location and size parameters to the Connector. I checked the Caliburn.Micro source and noticed that I'm actually creating a ChildWindow--not a Popup. Therefore, I just needed to set the Top and Left values of the settings for the dialog.

WPF User Control Library

namespace WpfUserControlLibrary {
    public static class Connector {
        public static void ShowDialog(System.Windows.Rect parent) {
            new AppBootstrapper();
            var windowManager = IoC.Get<IWindowManager>();

            // Popup is always 600 x 400
            dynamic settings = new System.Dynamic.ExpandoObject();
            settings.Left = (parent.Left + parent.Width / 2) - 300;
            settings.Top = (parent.Top + parent.Height / 2) - 200;

            windowManager.ShowDialog(new ShellViewModel(), settings: settings);
        }
    }
}

Outlook 2010 Add-in

var win = ThisAddIn.Application.ActiveWindow();
var parent = new System.Windows.Rect(win.Left, win.Top, win.Width, win.Height);
WpfUserControlLibrary.Connector.ShowDialog(parent);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文