C# WPF关于为启动屏幕显示图像的问题
我在我的项目中有一个形象 在解决方案资源管理器中,我创建了一个名为“资源”的文件夹,并在该文件夹中添加了一个图像 我想将图像设置为该文件夹中的文件。这是我的C代码 当我跑的时候,什么也没发生 这是我的XAML代码C# WPF关于为启动屏幕显示图像的问题,c#,wpf,visual-studio-2010,c#-4.0,splash-screen,C#,Wpf,Visual Studio 2010,C# 4.0,Splash Screen,我在我的项目中有一个形象 在解决方案资源管理器中,我创建了一个名为“资源”的文件夹,并在该文件夹中添加了一个图像 我想将图像设置为该文件夹中的文件。这是我的C代码 当我跑的时候,什么也没发生 这是我的XAML代码 <Window x:Class="Bail.SplashScreen" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.micros
<Window x:Class="Bail.SplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="256" Width="456" Background="#00005555" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen" >
<Grid Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image x:Name="splashScreenImage" Stretch="Fill" Grid.Row="0" />
</Grid>
</Window>
谢谢你的帮助。
这里是App.xaml,如果您需要查看
<Application x:Class="Bail.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="SplashScreen.xaml">
<Application.Resources>
</Application.Resources>
</Application>
我认为您必须在映像路径中指定子目录。你说是在“资源”里。因此,请尝试使用:
splashScreenImageSource.UriSource = new Uri("Resources/world_splash.jpg", UriKind.Relative);
编辑:您必须将文件类型设置为resource才能工作。如果要将其作为文件系统中的文件(而不是嵌入程序集中),则必须使用包uri,如:
splashScreenImageSource.UriSource = new Uri("pack://siteoforigin:,,,/Resources/world_splash.jpg", UriKind.Relative);
在这种情况下,请确保设置了文件的“复制到输出目录”选项
也考虑直接从XAML中进行初始化。它看起来更干净,需要的代码更少:
<Image x:Name="splashScreenImage" Stretch="Fill" Grid.Row="0" Source="Resources/world_splash.jpg" />
我想在我的应用程序中包含这些资源。当我分发它时,我不能确定它是否在文件系统上可用。
<Image x:Name="splashScreenImage" Stretch="Fill" Grid.Row="0" Source="Resources/world_splash.jpg" />