不包含“显示”的定义,也没有扩展方法“显示”错误

时间:2012-05-15 22:46:16

标签: c# wpf xaml

我正在尝试使用以下代码显示PluginManagerView的实例。

此XAML文件位于同一名称空间中,位于同一项目中。但是我在mainwindow.Show();的行中发现错误

Error 1 'PluginManager.PluginManagerView' does not contain a definition for 'Show' and no extension method 'Show' accepting a first argument of type 'PluginManager.PluginManagerView' could be found (are you missing a using directive or an assembly reference?) Blah procedyre .cs  30  24  PluginManager

谁能告诉我这个问题是什么?为什么不为MainWindow的先前用法抛出错误?

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.ComponentModel.Composition.Hosting;

namespace PluginManager
{
    public class PublicProcedures : Application
    {
        public static void ShowPlugins()
        {
            var mainwindow = new PluginManagerView();

            //An aggregate catalog that combines multiple catalogs

            var catalog = new AggregateCatalog();
            //Adds all the parts found in the same assembly as the Program class
            //catalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));
            catalog.Catalogs.Add(new DirectoryCatalog("./Plugins/"));

            var container = new CompositionContainer(catalog);

            var modules = container.GetExportedValues<IPlugin>();


            mainwindow.DataContext = modules;
            mainwindow.Show();
        }

    }


}

2 个答案:

答案 0 :(得分:1)

为了调用Window.Show(我猜你想做什么),PluginManagerView必须从类Window派生,而它的XAML必须看起来像这样:< / p>

<Window x:Class="PluginManager.PluginManagerView" ...>
    ...
</Window>

答案 1 :(得分:0)

抱怨无论PluginManagerView是什么,它都没有Show方法(您试图在名为“mainwindow”的PluginManagerView实例中调用)。