我有一个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
我的view
via中实例化constructor injection
。我该怎么做?
此外,我的m looking for best practices for
MEF /
MVVM 解决方案(一些示例代码将是一个好主意)。
ps .NET 4.5