jay_t55
jay_t55

Reputation: 11662

<Image /> displays image at design-time but not at runtime; why?

I'm trying to insert an image into my Windows Store app and it appears in design-time in the XAML editor but at runtime the image does not appear.

I'm pretty sure I'm using the right code here, and I have added the logo to the Assets folder however it still doesn't appear at runtime. If I got it wrong with the code or the Assets folder then it wouldn't even be appearing at design-time in the editor I think so what gives?

Image not appearing in Windows Store App

XAML:

<Page
    x:Class="AppName.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AppName"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Image Source="Assets\Logos\16380.png"
               Stretch="None"
               HorizontalAlignment="Left"
               VerticalAlignment="Top"
               Margin="120, 0, 0, 0"
               />
    </Grid>
</Page>

Upvotes: 0

Views: 174

Answers (1)

jay_t55
jay_t55

Reputation: 11662

I've managed to solve this problem.

When inserting images onto a page in XAML, you need to right-click the image file in Solution Explorer, click Properties and then make sure its Build Action is set to Content and then set Copy to Output Directory to Copy if newer. You also need to use forward slashes (/) and not back-slashes ().

Upvotes: 3

Related Questions