缺少 wpf window 的引用? .Show() 与其他显示功能一起丢失

Missing reference for wpf window? .Show() missing along with other display functions

我正在开发 Outlook 2016 VSTO 插件,我想向按钮添加 WPF window 显示功能。所以现在我的代码看起来像这样:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows;


namespace TaskManager 
{
    public partial class RibbonTaskManager
    {
        
        private void RibbonTaskManager_Load(object sender, RibbonUIEventArgs e)
        {
        }

        private void ButtonAddGroups_Click(object sender, RibbonControlEventArgs e)
        {
            FormAddGroups formAddGroups = new FormAddGroups();
            formAddGroups.Show();
        }
    }
}

问题是 formAddGroups 显然不包含“显示”的定义。我试图寻找可能丢失的引用但无济于事。 我加了

System.xaml

WindowsFormsIntegration

PresentationCore

PresentationFramework

我也找到了 this 话题,但我认为接受的答案解决了不同的问题。

您不能在 UserControl 上调用 Show(),但可以创建 window 并将其 Content 属性 设置为您的 UserControl:

var window = new System.Windows.Window();
window.Content = new FormAddGroups();
win.Show();