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

后端 未结 10 1884
有刺的猬
有刺的猬 2020-12-29 20:26

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 re

相关标签:
10条回答
  • 2020-12-29 20:34

    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.

    0 讨论(0)
  • 2020-12-29 20:39

    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.

    0 讨论(0)
  • 2020-12-29 20:40

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

    You will get the all.

    0 讨论(0)
  • 2020-12-29 20:41

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

    <Image Source="/bug.png"/>
    
    0 讨论(0)
  • 2020-12-29 20:46

    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();
    }
    
    0 讨论(0)
  • 2020-12-29 20:47

    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.

    0 讨论(0)
提交回复
热议问题