2016-12-26 33 views
0

私は複数のフォームを使用しているWPFアプリケーションを使用しています。 MainWindow.xamlとして知られているアプリケーションを起動すると開くメインフォームが1つあります。このフォームには、ユーザーオプションに応じて開かれる複数のフォームがあります。書式はStartClassWindow.xamlです。現在私はこのフォームに取り組んでいるので、MainWindow.xamlの代わりに直接開始したいと思っています。エラー:タイプに一致するコンストラクタが見つかりません

<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> 

しかし、その後、それは以下のようなエラーを与え始め:だから私はapp.xaml startupuriを変更これを行うには、パラメータを追加する必要があります

namespace Class 
{ 
    public partial class StartClassWindow : System.Windows.Window 
    { 

     public StartClassWindow(string classData) 
     { 
      InitializeComponent(); 
      className = classData; 
      function(); 
     } 
     //rest of the code. 
    } 
} 

答えて

3

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がありますあなたの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(); 
} 
関連する問題