Question

I'm trying to add images in my windows phone 8 application. There are two images located in "Assets/Icons/ " folder in the project, those images being "user.png" and "key.png". When I add them to the page (or anyother image), those are displayed in the designer view, but when I deploy the application on my phone (Lumia 520, can't run on emulator since I don't have windows 8.1 pro) images are not being displayed. If I change the image to Assets/ApplicationIcon.png the image is displayed when the application is deployed.

Here's the xaml code for the page.

    <Grid x:Name="LayoutRoot" Background="Beige">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="7*"/>
        </Grid.ColumnDefinitions>
        <Image Source="Assets\Icons\user.png" VerticalAlignment="Bottom" Grid.Row="0"   Grid.Column="0" Height="74" RenderTransformOrigin="1.99,0.542" Margin="-2,0,2,0"/>
        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Bottom">
            <TextBlock x:Name="User_Tag" Text=" User Name" FontSize="25" Foreground="LightGray"/>
            <TextBox x:Name="User_Name" Background="LightGray"/>
        </StackPanel>
        <Image Source="Assets\Icons\key.png" VerticalAlignment="Top" Grid.Row="1" Grid.Column="0" Height="74" RenderTransformOrigin="1.99,0.542" Margin="0,32,0,0"/>
        <StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Top">
            <TextBlock x:Name="Password_Tag" Foreground="LightGray" Text=" Password"   FontSize="25" />
        <PasswordBox x:Name="Password_Box" Background="LightGray"/>
        </StackPanel>


    </Grid>
Was it helpful?

Solution 2

The Designer can find images in a directory even if they are not included in the vs project or set as build content. After the build, the image might not be packed and acessible.

make sure you include the image in you VS projekt and set the BuildAction to "Content"

OTHER TIPS

Please set Soure like this, if images are not located at root level:

Source="/Assets/Icons/user.png"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top