System.Windows.Window.Activate()无法实现Microsoft.Office.Interop.Word.Window.Activate(),因为它没有匹配的返回类型?

时间:2014-03-10 13:15:04

标签: c# .net wpf windows office-interop

//第1行出错:无法实现'Microsoft.Office.Interop.Word.Window.Activate()'//因为它没有匹配的返回类型'void'。 //有人帮我解决了这个错误

public partial class Window1 : Window 
{
    public Window1()
    {
        InitializeComponent();
    }

    private void btnSelectWord_Click(object sender, RoutedEventArgs e)
    {
        // Initialize an OpenFileDialog 
        OpenFileDialog openFileDialog = new OpenFileDialog();


        // Set filter and RestoreDirectory 
        openFileDialog.RestoreDirectory = true;
        openFileDialog.Filter = "Word documents(*.doc;*.docx)|*.doc;*.docx";


        bool? result = openFileDialog.ShowDialog();
        if (result == true)
        {
            if (openFileDialog.FileName.Length > 0)
            {
                txbSelectedWordFile.Text = openFileDialog.FileName;
            }
        } 
    }

1 个答案:

答案 0 :(得分:2)

此问题可能由两个名称空间Microsoft.Office.Interop.WordSystem.Windows引起。请尝试以下操作以帮助编译器选择正确的类型:

public partial class Window1 : System.Windows.Window