获取参数的WPF主窗口
我需要在主窗口构造函数中注入一个记录器来启动WPF应用程序。获取参数的WPF主窗口,wpf,Wpf,我需要在主窗口构造函数中注入一个记录器来启动WPF应用程序。 使用参数启动MainWindow()的流程是否正常? (我读了这个“”,但我并没有按照他们的建议去做……) 公共部分类应用程序:应用程序 { 私有void应用程序\u启动(对象发送方、StartupEventArgs e) { ILOGingService logger=新的NLogService(string.Format(“testLogger”); MainWindow mainWindows=新的主窗口(记录器); mainW
使用参数启动MainWindow()的流程是否正常?
(我读了这个“”,但我并没有按照他们的建议去做……)
公共部分类应用程序:应用程序
{
私有void应用程序\u启动(对象发送方、StartupEventArgs e)
{
ILOGingService logger=新的NLogService(string.Format(“testLogger”);
MainWindow mainWindows=新的主窗口(记录器);
mainWindows.Show();
}
公共部分类主窗口:窗口
{
公共主窗口(iLogginService logger)
{
初始化组件();
this.logger=记录器;
}
当然可以:)你担心什么?你提到的问题中显示的方法也可以。为了验证我没有犯错误:)
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
ILoggingService logger = new NLogService(string.Format("testLogger"));
MainWindow mainWindows = new MainWindow(logger);
mainWindows.Show();
}
public partial class MainWindow : Window
{
public MainWindow(ILoggingService logger)
{
InitializeComponent();
this.logger = logger;
}
<Application x:Class="Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">