Answered by:
<image...> tag not working in XAML/C# Windows 8 App

Question
-
I am teaching myself how to program, and am starting with the very basics of creating a Windows 8 app. Using Visual Studio 2013 Express, and a new Blank project in XAML/C#.
I want to show a basic image on my all main page, and am trying to use the <image> tag in XAML file but it never shows a picture. This is what the tag code looks like:
<ImageSource="C:\Temp\Test.jpg"Width="100"Height="100"Margin="120,0,0,0"/>
It shows the object in the design view at the correct location but shows just an empty shell there. When I build my project and run it on "Local Machine", and image is never there.
Am I misunderstanding how this image tag works?
Sean
Saturday, November 2, 2013 7:37 PM
Answers
-
I figured it out. Didn't realize I had to add it as an asset in Visual Studio and set that to Content build action, and not the XAML page.
Thanks
- Marked as answer by Xiaoliang Chen - MSFTModerator Thursday, November 14, 2013 10:08 AM
Saturday, November 9, 2013 8:02 PM
All replies
-
your app doesnt have access to c:\temp so cant use that image
place the image in your project and make sure the build action is set to content (propertiy window) when its in the same folder as the xaml file (or the root of the project just write: test.jpg
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Proposed as answer by Ibraheem Osama MohamedMVP Saturday, November 2, 2013 8:35 PM
Saturday, November 2, 2013 7:39 PM -
:( I moved my JPG into the directory with my XAML file. Set the Build Action for the MainPage.xaml to "Content" and get the following error:
Error 1 'MyTest.MainPage' does not contain a definition for 'InitializeComponent' and no extension method 'InitializeComponent' accepting a first argument of type 'MyTest.MainPage' could be found (are you missing a using directive or an assembly reference?) C:\Users\....\MainPage.xaml.cs 28 18 MyTest
Sunday, November 3, 2013 12:46 AM -
I figured it out. Didn't realize I had to add it as an asset in Visual Studio and set that to Content build action, and not the XAML page.
Thanks
- Marked as answer by Xiaoliang Chen - MSFTModerator Thursday, November 14, 2013 10:08 AM
Saturday, November 9, 2013 8:02 PM