2016-12-26 41 views
0

找到沒有匹配的構造函數我有一個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. 
    } 
} 

回答

3

您需要添加一個參數您的StartClassWindow這樣的無構造:

public StartClassWindow(string classData) 
{ 
    InitializeComponent(); 
    className = classData; 
    function(); 
} 

public StartClassWindow() 
{ 

} 

或者,如果你不希望有另一個構造函數,你可以覆蓋App.xaml.csOnStartup方法,但你應該刪除App.xaml第一StartupUri="StartClassWindow.xaml"。如下所示:

protected override void OnStartup(StartupEventArgs e) 
{ 
    StartClassWindow st = new StartClassWindow(""); 
    st.Show(); 
}