我有一个 WPF 应用程序,我想以编程方式显示内容。但是当我尝试按特定顺序执行此操作时,它无法显示。
这有效
public partial class MainWindow : Window
{
private static GX3Logger logger = GX3Logger.GetLogger();
private GX3ClientMain.GX3ClientMain clientMain = null;
/// <summary>
/// Main method
/// </summary>
/// <param name="args">
/// Application args
/// </param>
///
public MainWindow()
{
InitializeComponent();
Button btn = new Button();
btn.Content = "Moo";
btn.Height = 100;
btn.Width = 100;
stackPanel1.Children.Add(btn);
}
public int Initialise(string[] args)
{
........
}
}
这不
public partial class App : Application
{
void app_Startup(object sender, StartupEventArgs e)
{
MainWindow mw = new MainWindow();
mw.Initialise(e.Args);
}
}
public partial class MainWindow : Window
{
private static GX3Logger logger = GX3Logger.GetLogger();
private GX3ClientMain.GX3ClientMain clientMain = null;
/// <summary>
/// Main method
/// </summary>
/// <param name="args">
/// Application args
/// </param>
///
public MainWindow()
{
InitializeComponent();
}
public int Initialise(string[] args)
{
Button btn = new Button();
btn.Content = "Moo";
btn.Height = 100;
btn.Width = 100;
stackPanel1.Children.Add(btn);
.......
}
}
为什么不?