错误:在类型
问题描述:
找到没有匹配的构造函数我有一个WPF应用程序,我使用多个窗体。有一个主要表格在我们启动应用程序时被打开,它被称为MainWindow.xaml
。这个表单有多种形式,根据用户选项打开。有一个表格StartClassWindow.xaml
。目前我正在处理这个表格,所以我希望它直接开始而不是MainWindow.xaml
。因此,要做到这一点,我改变了app.xaml startupuri
:错误:在类型
<Application x:Class="Class.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DispatcherUnhandledException="Application_DispatcherUnhandledException"
StartupUri="StartClassWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
但后来它开始给错误象下面这样:
No matching constructor found on type 'Class.StartClassWindow'. You can use the Arguments or FactoryMethod directives to construct this type.' Line number '3' and line position '9'.
这里是StartClassWindow.xaml.cs
:
namespace Class
{
public partial class StartClassWindow : System.Windows.Window
{
public StartClassWindow(string classData)
{
InitializeComponent();
className = classData;
function();
}
//rest of the code.
}
}
答
您需要添加一个参数您的StartClassWindow
这样的无构造:
public StartClassWindow(string classData)
{
InitializeComponent();
className = classData;
function();
}
public StartClassWindow()
{
}
或者,如果你不希望有另一个构造函数,你可以覆盖App.xaml.cs
的OnStartup
方法,但你应该删除在App.xaml
第一StartupUri="StartClassWindow.xaml"
。如下所示:
protected override void OnStartup(StartupEventArgs e)
{
StartClassWindow st = new StartClassWindow("");
st.Show();
}