gpt4 book ai didi

c# - WPF 主窗口覆盖 OnStartup

转载 作者:行者123 更新时间:2023-11-30 22:09:10 25 4
gpt4 key购买 nike

如果不使用 StartupUri,我就无法显示我的主窗口。OnStartup 不触发。

我从 App.xaml 中删除了 StartupUri

<Application x:Class="SCon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Application>

在后面的代码中添加了以下内容

    protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
SCon.MainWindow.Instance.Show();
}

MainWindow 是一个单例

    private static volatile MainWindow instance = null;
private static object lockThis = new object();
public static MainWindow Instance
{
get
{
if (instance == null)
{
lock (lockThis)
{
if (instance == null)
{
instance = new MainWindow();
}
}
}
return instance;
}
}

最佳答案

了解您的意思或卡在什么地方。我会检查 App.xaml 的构建操作,然后查看此站点。

http://www.erikojebo.se/Code/Details/202

这家伙解释的很好:)

此外,您的问题有点重复。检查一下:How to change StartupUri of WPF Application?

关于c# - WPF 主窗口覆盖 OnStartup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21712053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com