不包含“Show"的定义且没有扩展方法“Show"错误 [英] Does not contain a definition for 'Show' and no extension method 'Show' error
问题描述
我正在尝试使用以下代码显示 PluginManagerView 的实例.
I am trying to show an instance of PluginManagerView with the below code.
此 XAML 文件位于同一个命名空间、同一个项目中.但是我在 mainwindow.Show();
的那一行出现了一个错误,说
This XAML file is in the same namespace, same project. But I got an error at the line of mainwindow.Show();
saying that
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 的用法抛出错误?
Can anyone tell me about what the problem is? And why doesn't it throw the error for the prior usages of 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();
}
}
}
推荐答案
为了调用 Window.Show(我猜这就是您想要做的),PluginManagerView 必须从 Window,它的 XAML 必须看起来像这样:
In order to call Window.Show (which i guess is what you want to do), PluginManagerView would have to be derived from class Window, and its XAML would have to look somehow like this:
<Window x:Class="PluginManager.PluginManagerView" ...>
...
</Window>
这篇关于不包含“Show"的定义且没有扩展方法“Show"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!