Search code examples
windowsxamlemulationdesigner

Image in button is rendering in the designer but not the windows phone emulator (Windows App Developement)


The designer loads with the image as the button but the emulator loads without the image. I can conjecture that it might be an 'image rendering beyond screen' issue. Any suggestions with the code would be appreciated.

The designer is perfectly visible with two images dividing the screen(supposedly buttons), while the emulator shows half the screen black and rest of it as grey divided horizontally.

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height=".5*"/>
            <RowDefinition Height=".5*"/>
        </Grid.RowDefinitions>

        <Button 
            x:Name="CricketButton" Grid.Row="0"
            Height="auto" Width="auto"
            HorizontalAlignment="Stretch" 
            Margin="-5" VerticalAlignment="Stretch"  
            Click="CricketButton_Click"
            FontSize="25" RequestedTheme="Light" Opacity="0.9" BorderThickness="0">
                <Image Source="Assets\cricket-hd-wallpapers.jpg" Stretch="Fill" Opacity="0.7"/>
                <!--<TextBlock Text="Cricket" HorizontalAlignment="Right"  VerticalAlignment="Bottom"  Foreground="White" 
                           FontSize="72"/>-->
        </Button>

        <Button 
            x:Name="Football" Grid.Row="1"
            HorizontalAlignment="Stretch" 
            Height="auto" Width="auto"
            Margin="-5"
            VerticalAlignment="Stretch"
            Click="Football_Click"
            FontSize="25" 
            RequestedTheme="Light" Opacity="0.9" Background="#FFC7C7C7" BorderThickness="0">
                <Image Source="Assets\real-madrid-granada.jpg" Opacity="0.9" Stretch="Fill"/>
        </Button>
    </Grid>

Solution

  • It is probably not able to resolve the file location during run time. You need to make sure you include the image in the Build.

    http://www.wpfsharp.com/2012/01/23/using-relative-path-images-included-as-content-with-wpf/