私は持っていViewます:
internal partial class StartWindow : Window
{
public StartWindow()
{
InitializeComponent();
}
[ImportingConstructor]
public StartWindow(IStartWindowViewModel viewModel)
:this()
{
ViewModel = viewModel;
}
public IStartWindowViewModel ViewModel { get; private set; }
}
そして適切なViewModel:
[Export]
internal class StartWindowViewModel : IStartWindowViewModel
{
public IEnumerable<Customer> Customers { get; set; }
}
UPD (@Blachshma の回答に基づく): コードを使用して StartWindow ビューをアプリに挿入できません:
public class App
{
[ImportingConstructor]
public App(StartWindow window)
{
// Do whatever you need
}
パラメーターなしのコンストラクターは App.g.cs によって必要とされるため:
internal partial class App : System.Windows.Application {
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public static void Main() {
TransparentNotification.App app = new TransparentNotification.App();
app.Run();
}
}
app.csここで、viewviaでインスタンス化したいと思いますconstructor injection。私はそれのために何をすべきですか?
また、m looking for best practices forMEF /MVVM` ソリューション (このためのサンプル コードは素晴らしいアイデアです)。
PS .NET 4.5