david gvetadze
david gvetadze

Reputation: 11

Images shows in design mode but not at runtime in WPF .net Core Project

I am using pack uri to get the image. It works well in design mode. The image shows without a problem but nothing appears at runtime. I am working in WPF .net Core application. Basically, I have two projects and I am trying to add the image from another project(same solution). I have added the reference for the project and set the image build action to resource already but still nothing happens.

<Image Source="pack://application:,,,/Test;component/Images/1.png" width="auto" height="auto"/>

This is the mainWindow.xaml code. Test is the name of another project. The exact same code works without problem in .Net Framework WPF application.

Upvotes: 0

Views: 959

Answers (2)

st35ly
st35ly

Reputation: 1255

I ran into similar issue couple months ago during upgrading WPF applicating from .NET Frw to .NET Core.

Make sure that your resource in VS explorer is set to be in Build Action = "Resource"

enter image description here

and use this syntax as in the example below to referencing it for your XAML Image control:

pack://application:,,,/Resources/Images/gray.png

Upvotes: 0

david gvetadze
david gvetadze

Reputation: 11

If anyone has this problem How can I reference a resource (png) from a seperate project in the same solution check this post. Basically your project sdk in .csproj file should look like this: <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop>.

Upvotes: 1

Related Questions