SplashScreen IOException

Jal*_*afa 5 c# wpf resources splash-screen

SplashScreen s = new SplashScreen(System.Reflection.Assembly.GetExecutingAssembly(),"splash.png");
s.Show(false);
Run Code Online (Sandbox Code Playgroud)

调用s.Show()参数是否为false或时true,它将IOException 与消息一起抛出

找不到资源“ splash.png”

即使将splash.png添加到资源中,并且其Build ActionResource

在WPF中使用图像以及Image控件时,我已经注意到许多问题。

Jal*_*afa 5

根据“我的代码无效,我不知道为什么。我的代码有效,我不知道为什么”的原则,我已经解决了这个问题。

首先,我将启动图像的构建动作设为Resource。(将图像放入“ 嵌入式资源”无法解决问题)。

第二,我的代码是:

SplashScreen s = new SplashScreen("resources/splash.png");
s.Show(false);
/* do some things */
s.Close(Timespan.FromMilliseconds(300));
Run Code Online (Sandbox Code Playgroud)