views:

4743

answers:

6

I have a project which requires an image in the window. This is a static image and i added through 'Add>Existing Item'. It exists in the root of the project.

I reference the image in a test page like so -

<Page x:Class="Critter.Pages.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test">
<Image Source="bug.png"/>

Problem is i get a message saying it can't be found or it's build action isn't resource but it DOES exist and it's build action IS resource. If i create a new application and just throw it on a window then it works fine.

Any help would be great.

+5  A: 

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
Cameron MacFarland
Thanks dude. that worked a treat! Still don't really get those Pack URIs but the full rebuild did the trick.
Stimul8d
+8  A: 

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.

brianstewey
Thank you - that was the solution!
Stiefel
+2  A: 

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.

TheBill
+1  A: 

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();


    }
pigleg
+1  A: 

I got the same issue. Closed solution adn re-opened. Then all works fine.Thanks.

Rajesh
+1  A: 

it does exactly solve the problem, the restart of vs 2008. hope there will be developing a patch at least to address this

andol