While developing a project for Windows Phone 7, I'm adding an image control onto the Grid and using the following code in C# to set the image source:-
Uri nUri = new Uri("/TestImage.png", UriKind.Relative);
BitmapImage nBitmapImage = new BitmapImage(nUri);
FacebookImage.Source = nBitmapImage;
The problem is that whenever I use custom images, they do not show up when I build and run the app on the emulator. Whereas, if I change the image file name in the above code to one of the images that are included in the project by default (ApplicationIcon.png), the image shows up upon running. I would like to know if this is a problem with the code or with the custom image files I'm using. I'm ensuring that the images I'm creating are proper and have the same attributes as the images included by default.
Could someone please help me out with this.
Thanks.
Click on your custom picture in Visual Studio's Solution Explorer. Then, look at the property window (press F4 if it's closed), and at the "Build Action" line. It basically tells the compiler how to embed your file in the application. The build action of ApplicationIcon.png should be "Content", just set the same one for your custom pictures.
Related
I'm converting an app to run as a Universal Windows App using VS 2015 Community. If I create a webview using the toolbox, I can enter "http://www.google.com" into the Source property, and it will display google.
If I use the drop down on the Source property to reference (say) Help.htm as a local resource, the source windows displays "ms-appx:///Help.htm". Similarly if it is in Assets, it displays "ms-appx:///Assets/Help.htm". When I run the program, where the webview should appear it displays "You will need a new app to display this ms-appx" and invites me to search the store.
I can display a local image in an image box with very similar syntax, with Source being "ms-appx:///Assets/StoreLogo.png". The Source property in this case is in the "common" group, not "miscellaneous", but apart from that appears virtually identical.
Nor can I specify a local path in a URI (although again I can display Google). Behaviour is identical on two different machines. I have spent several days trying to work out what is going on; any suggestions?
Can you please try to load file through code and share results?
public MainPage()
{
this.InitializeComponent();
mywebview.Source = newUri("ms-appx-web:///Help.htm");
}
also try this
mywebview.Navigate(newUri("ms-appx-web:///Help.htm"));
If both above options doesn't work. Please change to below and share results
mywebview.NavigateToString("<Html><Body><h1>Eureka!!!!<h1><Body></Html>");
If you are using it from a Library project, you must also add the name of the library, like that:
ms-appx-web:///[Library]/Help.htm
I am currently building a Windows Universal App and the learning curve is OK. I get a response from my webservice, parse the JSON, display info in the app, but my current issue is the following one:
I tried to display an image that I put in the Assets folder, but this doesn't seem to work.
This is my layout:
As you can see, the text "Test" is correctly displayed but not the images.
On the right side, in the explorer pannel, I cannot see the files that should be here:
WHAT I HAVE TRIED:
In my example, they are in the Assets/picto folder, but I have also tried the root directory Assets, as wal as creating Image folder at the same level.
I have definitely no idea how to add a simple picture, so any help is appreciated!
Adding items in Windows explorer to the right location doesn't add them to your solution / deployment.
You have to right-click the picto folder -> Add > -> Add existing item. Your items are not even in your solution, so they won't show up on the layout screen.
Make sure you set the correct build target for each image.
If an image shouldn't show up, even through it's in your solution, this is often the reason.
I'm trying to create a Windows 8.1 store app, and I need to add a button to it.
The button should display an image.
I add the image to the assembly in Solution Exploreras Artwork/Pencil.png
I add the button to the UI
Using the property editor for the button, I select Foreground image.
The designer shows a list of available images from the assembly, I choose the image.
The designer shows the selected image (partially).
The button remains blank.
I tryied playing around with different content types (of the image), as Content, Embedded resource, Do not copy, Copy if newer.
The image is not visible either at design or run time.
I found tons of articles from 2005 to 2012 about this problem in WPF. Tryed to change the image source (although I think the designer should set it correctly):
Pencil.png
Artwork/Pencil.png
pack://siteoforigin:,,,/Pencil.png
pack://siteoforigin:,,,/Artwork/Pencil.png
pack://application:,,,/Pencil.png
pack://application:,,,/Artwork/Pencil.png
Any ideas?
To make the environment clear:
Visual Studio 2013 Update 2
Project type: Visual C#/Store Apps/Windows Apps/Blank App
Target: Windows 8.1
It seems that the correct combination (to display an image on a Windows 8 app button) is:
set it as backbround image (as opposed to foreground)
set the file to be "PRIResource" (as opposed to "Embedded resource")
use the designer to specify the image (which will generate a reference like this "Artwork/Pencil.png")
:-(
It works design-time, but it does not work runtime.
Here's one that works both design-time and runtime:
set it as backbround image (as opposed to foreground)
set the file to be "Content", "Copy if newer"
use the designer to specify the image (which will generate a reference like this "Artwork/Pencil.png")
I have a Page in a Windows Phone class library. This page has an appbar. I would prefer everything this page needs to be included within the class library so the setup list for consumers of this page / assembly is minimal.
However, When I set ApplicationBar icons, they get added to the class library project under the folder 'icons' just like normal, they show up fine in Blend, but at runtime they are no where to be found!
When I put the icons in the Windows Phone Application project all is well. However this is not my desired scenario as it is additional configuration / setup by the application author to use my pages.
I tried using the resource pathing using /{AssemblyName};component/icons/{IconName} but of course the AppBar needs them to be of type "Content" not "Resource". So I am thinking this is impossible but I wanted to know if anybody out there figured out how to do this.
Sorry guys. I just figured it out. I changed the newly added icons from "Resource" to "Content" but I forgot to set "Copy if newer" so they weren't getting outputted to the Bin\Debug\icons folder of the windows Phone Application. something to keep an eye on I guess.
I'm starting my first PhoneGap project and am developing using Visual Studio and Windows Phone 7, although I intend on ultimately deploying to iOS and Symbian as well.
However, I'm stuck at Step 1. I have added an image to the www/images folder, and put the following code:
<img src="images/login-btn.png" width="103" height="42" style="margin-left:90px;" />
And I get:
It works fine when I preview it in IE9, but I don't have a Mac to test it on iOS yet.
It's worth noting that the JS files and CSS have loaded fine, it's just any image (whether referenced in CSS or an <img> tag) always comes up broken.
My guess would be the Build Action of your image file is incorrect.
According to http://wiki.phonegap.com/w/page/48672055/Getting%20Started%20with%20PhoneGap%20Windows%20Phone%207#4Reviewtheprojectstructure section 4. You should be setting the Build Action of your images etc to Content which simply copies them into the output project when it is built. They are probably currently set to Resource or None.
To change the Build Action right click a file and choose properties to go to the properties window if you do not already have it open. It is probably then the first property. Just click and choose the correct one.
I'm posting this to questions that I found while trying to find my answer to the same problem. The JS framework I use adds a url query to each image when in a debugging mode (in order to force browsers to reload image, instead of using cached). So, my image "image/background.jpg" would be accessed as "image/background.jpg?d=34342233". But, when running on PhoneGAP for Windows Phone, it won't recognize the image, and thus it shows up as broken. So, I had to turn off debugging for the framework I use, and suddenly the images showed up (still, don't forget to set the Build Action to "Content" as mentioned earlier).