简体   繁体   中英

Image XAML tag (Win8) not working with some paths

The Source attribute of the Image tag works only with the files which were added to the 'Assets' folder in the Solution Explorer.

I've got two files in the Assets directory: Logo.png and Logo2.png, but only Logo.png is added to 'Assets' in the Solution Explorer. This image works properly:

<Image Source="/Assets/Logo.png"/>

while this image doesn't show up:

<Image Source="/Assets/Logo2.png"/>

File paths like 'C:\\Users\\user\\Pictures\\img.jpg' don't work either. Is it possible to access images which are not specified in the 'Assets' folder in the Solution Explorer?

EDIT:

Here is what I do:

  1. Create new project in VS2012: Visual C# -> Windows Store -> Blank App (XAML)
  2. Open MainPage.xaml
  3. Choose Image from Toolbox and draw an image element in the Design mode
  4. The only working value for the Source attribute is '/Assets/Logo.png'. These are not working: 'C:\\images\\img.jpg', '/Assets/Logo2.png', 'Project_name;component/Assets/Logo.png', 'Project_name;component/Assets/Logo2.png', etc.

Here is the format you will want to use:

Project;component/ImagePath

Where Project is the name of the assembly (project in most cases) that you want to reference, and "component" specifies that the assembly being referred to is referenced from the local assembly.

So for the Logo2, you would do:

<Image Source="ImageDemo;component/Assets/Logo2.png" Name="custLogo"/>

Where "ImageDemo" is the project name and "Assets/Logo2.png" is the path inside project.

As for absolute paths, the following worked just fine for me:

<Image Source="C:\Images\001.jpg"></Image>

Ok, here's what I've found out:

Windows Store Apps (Win8) have got limited access to files. So I can only use the files which are shipped with the application. However, it is possible to get the user's files if he chooses them in a file picker.

There is also a great sample here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM