【问题标题】:show dialog with WPF window under Outlook VSTO add-in在 Outlook VSTO 加载项下显示带有 WPF 窗口的对话框
【发布时间】:2015-11-30 08:22:00
【问题描述】:

我创建了 Outlook VSTO 应用程序。单击按钮时,我想弹出一个 WPF 窗口对话框。这是我的 WPF 窗口:

<Window x:Class="WorkflowSR.View.ArchiveSettingWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WorkflowSR.View"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <CheckBox x:Name="checkBox" Content="CheckBox" HorizontalAlignment="Left" Margin="111,73,0,0" VerticalAlignment="Top" Width="100"/>
    </Grid>
</Window>

在代码中,当我想打开对话框时,我会这样做:

var archiveSettingWindow = new ArchiveSettingWindow();
archiveSettingWindow.owner = ???
archiveSettingWindow.ShowDialog();

我应该为窗口所有者设置什么?谢谢。

【问题讨论】:

    标签: c# wpf outlook vsto outlook-addin


    【解决方案1】:

    使用 IOleWindow 和 WindowInteropHelper:

            using System.Runtime.InteropServices;
            ...
            IntPtr wnd = new IntPtr(0);         
            object window = _application.ActiveWindow();
            if (window != null)
            {
                IOleWindow oleWindow = window as IOleWindow;
                if (oleWindow != null)
                {
                    oleWindow.GetWindow(out wnd);
                }
            }
            ...
    
            if (wnd != IntPtr.Zero)
            {
                WindowInteropHelper helper = new WindowInteropHelper(archiveSettingWindow);
                helper.Owner = wnd;
                archiveSettingWindow.ShowInTaskbar = false;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-21
      相关资源
      最近更新 更多