c# - WPF InitializeComponent() 在使用 SplashScreen Buid Action 添加图像时给出 CS0103 错误
问题描述
我面临着一些我无法向自己解释的奇怪问题(因此修复):在我的 C# 应用程序中,我有 3 个 WPF Windows 会在调用时弹出。当然,所有这些 WPF 窗口都有该InitializeComponent()
方法。
我还创建了一个SplashWindow
自定义类,我在其中定义了一个 SplashScreen 通用窗口。需要一个Uri
对象作为输入,它将弹出一个启动屏幕,其中包含引用该 Uri 的图像,然后在调用关闭方法时关闭。我用于启动画面的图像加载到我的解决方案中名为Resources的文件夹中,并且Build Action设置为SplashScreen。这是代码:
class SplashWindow
{
private Form form = null;
public SplashWindow(Uri uri)
{
form = new Form();
StreamResourceInfo info = System.Windows.Application.GetResourceStream(uri);
Image splashImage = Image.FromStream(info.Stream);
// Get image dimensions
form.Width = splashImage.Width;
form.Height = splashImage.Height;
form.BackgroundImage = splashImage;
form.BackgroundImageLayout = ImageLayout.Stretch;
form.StartPosition = FormStartPosition.CenterScreen;
form.FormBorderStyle = FormBorderStyle.None;
form.TopMost = true;
form.Show();
}
internal void CloseSplash()
{
form.Close();
}
}
我在我的代码中调用了这个闪屏对象,如下所示:
// Start async to get user
Task<User> getUser = GitHubConnection.LoginAsync(tok);
// Pop up splash screen in the meantime
SplashWindow splash = new SplashWindow(validationUri);
// Await for user
User user = await getUser;
// Close splash screen
splash.CloseSplash();
这非常有效!
我面临的问题是,如果我尝试将另一个图像添加到我的解决方案并将构建操作设置为 SplashScreen 到新更新的图像,那么InitializeComponent()
我所有 WPF 窗口中的所有方法都会开始给出 CS0103 错误:The name InitializeComponent does not exist in current context
。所以这就像我不能使用多个启动画面,但这对我来说没有任何意义。
知道为什么会这样吗?我错过了什么?
解决方案
推荐阅读
- swift - 如何从服务器下载图像并快速显示淡入淡出动画?
- python-3.x - 如何通过将方法名称传递给函数参数来调用python的get或请求库的任何方法?
- c# - 为什么实体框架不为我的第二个查询使用 ReadUncommitted?
- java - jar 文件打不开
- css - 如何正确定位径向渐变背景?
- macos - 如何在 macOS mojave 的终端中为文件扩展名设置默认应用程序?
- reactjs - 如何将 api 中的数组作为道具传递给另一个组件
- angular - Jest for Angular cobertura 文件重命名
- python - 如何使用 filediscriptor 3 将音频流式传输到对话流
- r - 需要帮助改进此 GIF 外观,而它在闪亮的内部运行