Image shows up in Visual Studio designer but not during run-time

后端 未结 19 1816
独厮守ぢ
独厮守ぢ 2020-12-17 08:09

I\'m currently working w/ VS studio 2010, .NET 4.0. Here is my scenario:

I currently have a class library project called \"Images\" that contains a sub folder calle

相关标签:
19条回答
  • 2020-12-17 08:11

    Maybe this helps someone with Visual Studio 2019. I was missing a simple /

    Steps: Right Click Project -- Add > Existing Item -- Select Picture to add -- Click on picture in visual Studio -- go to properties -- change Build Action to > Recources

    no we go into Xaml and add your resource

    <UserControl.Resources> <Image x:Key="ButtonImage" Source="/image.jpg"/> </UserControl.Resources>

    the / before the image name is a must. Without the / it will show up as working in xaml but once you start the program it wont show.

    <Button Content="{StaticResource ButtonImage}"></Button>
    

    I hope that fixes it if you read this

    0 讨论(0)
  • 2020-12-17 08:14

    The following worked for me:

    • Build Action = Resource

    • Copy to Output Directory = Do not copy

    xaml:

    <Image Source=“Rsources/myPic.png”/>
    

    Where “myPic.png” is the image inside “Resources” folder

    0 讨论(0)
  • 2020-12-17 08:15

    Well, I waisted more than 3 hours of my time on this problem. Your answers helped me to partially solve the problem and that's what urged me to add to this useful discussion.

    I got my problem solved as:

    1. select all images in your solution explorer resources.
    2. Right click and go to properties.
    3. Build action to "Embedded Resource"
    4. Copy to Output to "Copy Always"
    5. save and build solution.
    6. add image and take care or the ZIndex value.
    7. After all of that I found my self when I use the image multiple times or try to change to another image on the same image control to change the path for the image either on XAML or in the image control properties to be:

      source="pack:://siteoforigin:,,,/Resources/image.png"
      
    0 讨论(0)
  • 2020-12-17 08:15

    Please check image is included in solution or not. If image is not included then click on Show All Files from solution and then right click on image and select Include In Project option. After that it will work with relative path as well.

    Ex:

    " Source="/Images/Logo/close.png" "

    0 讨论(0)
  • 2020-12-17 08:18

    Maybe the Image does not have the Build Action set to Resource. If it's anything else, including Embedded Resource, then it will not display properly at runtime.

    0 讨论(0)
  • 2020-12-17 08:20

    siteoforigin is for files copied to the executable directory or subdirectories, for resources you should use application as authority as far as i know.

    SiteOfOrigin:

    Path: The name of the site of origin file, including its path relative to the location from which the executable assembly was launched.

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