【问题标题】:Does not contain a definition for 'Show' and no extension method 'Show' error不包含“显示”的定义并且没有扩展方法“显示”错误
【发布时间】:2012-05-16 15:38:27
【问题描述】:

我正在尝试使用以下代码显示 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();
        }

    }


}

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    为了调用Window.Show(我猜这是你想要做的),PluginManagerView 必须从类Window 派生,并且它的 XAML 必须看起来像这样:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多