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

后端 未结 19 1819
独厮守ぢ
独厮守ぢ 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:23

    My image is not in the same project as my window

    I solve the problem going to Solution Explorer > "Project name" > Resources then select the image and change Build Action to Resource.

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

    This was driving me crazy. I tried lots of different things based on various articles but nothing worked. My xaml window and image are in a separate DLL from the executable assembly. Not sure if that was part of my problem.

    In the end I had success with:

    1. Make sure the image properties in the project has "Build Action" = "Resource", NOT "Embedded Resource"
    2. In the xaml, with the image tag selected, use the properties windows to select the Source dropdown since NOW the image appears in the dropdown list! This let visual studio format the string for me.

    The string visual studio formatted for my image was:

    <Image Source="/Paperless.Common;component/Resources/Checkbook.png" />
    

    where "Paperless.Common" was the name of my assembly, and "Checkbook.png" was my image that resided in a "Resources" folder.

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

    It could be as simple as what I just did earlier today. I placed the file in the folder without referencing it in the solution. It showed up fine during design.

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

    The easiest way is to just add the image to your project. Add a Resource folder to your project by right clicking on solution explorer -> Add -> Folder (Name it Resource) -> Right click the newly created Resource folder -> Click Add existing Item -> Find your image (select All Files)

    Add an image item to your xaml form selected. Under properties -> Common -> Source you should be able to just drop down and select your image

    Selecting from dropdown

    0 讨论(0)
  • 2020-12-17 08:26
    1. Just Drag & Drop folder "Icons" into your project "Images".
    2. Use relative path: Image Source="Icons/Button1.png".
    0 讨论(0)
  • 2020-12-17 08:27

    1- change the file image properties into resource , {click right on the image file-> choose Properties -> switch Build Action to Resource.

    2- use this tag to display image

     <Image Source="pack://application:,,,/[Put here the Main Namespace];component/[File path]"/>
    

    example

    <Image Source="pack://application:,,,/My;component/Resources/switch-off.png"/>
    
    | improve this answer | |
    0 讨论(0)
提交回复
热议问题