WPF - Image 'is not part of the project or its Build Action is not set to Resource'

喜欢而已 提交于 2019-11-30 05:43:43

Try doing a full rebuild, or delete the build files and then build the file.

Visual Studio doesn't always pick up changes to resources, and it can be a pain to get it recompile.

Also try using a full URI as that helped me when I had the same problem. Something like

pack://application:,,,/MyAssembly;component/bug.png
sona jha

→ Right click the image file → Click property → Select Build Action to Resource → Clean and Build solution → Run the Solution

You will get the all.

I had the same issue. Cleaning and rebuilding the solution didn't fix it so I restarted visual studio and it did. Here's hoping Visual 2010 fixes this issue and the many others that plauge wpf in Visual 2008.

Try starting the path to your image with a "/":

<Image Source="/bug.png"/>
towrywang

There is a solution to your question

<Image Source="/WpfApplication4;component/images/sky.jpg" />

"component" is not a folder!

It doesn't, or at least the current beta doesn't. I found this page while looking into exactly the same problem. Rebuild/clean did nothing. After closing down and reloading the solution the file magically became compatible again.

pigleg

Example of async load, another option. Example clip.mp4 is in the web project root.

void Landing_Loaded(object sender, RoutedEventArgs e)
{
    //Load video async

    Uri pageUri = HtmlPage.Document.DocumentUri;
    Uri videoUri = new UriBuilder(pageUri.Scheme, pageUri.Host, pageUri.Port, "clip.mp4").Uri;           

    WebClient webClient = new WebClient();
    webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
    webClient.OpenReadAsync(videoUri);
}

void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    byte[] VideoBuffer = new byte[e.Result.Length];
    e.Result.Read(VideoBuffer, 0, (int)e.Result.Length);
    MemoryStream videoStream = new MemoryStream(VideoBuffer);
    ContentVideo.SetSource(videoStream);
    ContentVideo.Stop();
    ContentVideo.Play();
}

I faced the exact same issue but restarting VS2008 or cleaning and rebuilding the project did not work for me. In the end, the below steps did the trick.

  • In Windows Explorer copy the Image into your project resource folder. Example: MyProject\Resources\
  • From within Visual Studio right click on the Resources and select "Add > Existing item" and select the image which you have just copied in
  • From within the form XAML set the image source as: "Source="Resources/MyImage.ico" (my image was saved as icon (.ico) file, but this approach should work for any image type

Hope this helps someone

JnuO

I had a similar problem. After I deleted a someStyle.xaml file that I wasn't really using from the solution explorer. Then I restored the file, but no change happened. Cleaning and rebuilding the project did not help.

Simply deleting the corresponding row:

<ResourceDictionary Source="someStyle.xaml"/> 

did the trick.

I had the same error message but my issues was a simple NOOB mistake.

When I added my .ico files to "My Project / Resources", VS made a sub folder named Resources and I was trying to use;

<Window Icon="icons1.ico">

when I should have been using;

<Window Icon="Resources/icons1.ico">

... don't judge, I started using WPF 1 week ago :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!