locked
ImageBrush Background not shown

    Question

  • I try to make my first  phone 8.1 app and I set Page.Background as ImageBrush.

    The trouble is that if I see the xaml preview in designer mode (VS Express 2013) tha background image is visible as I expect, but

    on phone emulator there is only black screen.

    I wonder if this is emulator's bug or maybe there is something I do wrong?


    Andrzej

    Tuesday, October 07, 2014 5:48 PM

Answers

  • Try set "ms-appx:///Assets/[image name]" and use StaticResource (not ThemeResources) and if you use this at only one page - write you brush only this page, not App.

    And you can try

    <Page ...>
    
      <Grid>
        <Grid.Background>
          <ImageBrush ImageSource="ms-appx:///Assets/[image name]" Stretch="UniformToFill" />
        </Grid.Background>
      </Grid>
    </Page>

    • Marked as answer by Andrzey Wednesday, October 08, 2014 4:53 AM
    Tuesday, October 07, 2014 7:05 PM

All replies

  • Hi, Andrzey.

    Can you show your code? Did you try start on another emulators or phone?

    Regards, Nikita.

    Tuesday, October 07, 2014 6:10 PM
  • In the App.xaml

    <Application.Resources>
            <ImageBrush x:Key="BackG" Opacity="1" ImageSource= "Assets\150x150.png" Stretch="UniformToFill"" />
        </Application.Resources>

    and in the MainPage.xaml

    <Page
        x:Class="DietPhone.BasicPage1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:DietPhone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Background="{StaticResource BackG}">

    ...

    </Page>

    The same behavoiur is when I apply the background to Grid

     <Grid x:Name="LayoutRoot"  Background="{ThemeResource BackG}">

    I wonder if the image 150x150.png is really installed on the emulator or maybe my path is wrong?


    Andrzej



    • Edited by Andrzey Tuesday, October 07, 2014 7:03 PM
    Tuesday, October 07, 2014 6:43 PM
  • Try set "ms-appx:///Assets/[image name]" and use StaticResource (not ThemeResources) and if you use this at only one page - write you brush only this page, not App.

    And you can try

    <Page ...>
    
      <Grid>
        <Grid.Background>
          <ImageBrush ImageSource="ms-appx:///Assets/[image name]" Stretch="UniformToFill" />
        </Grid.Background>
      </Grid>
    </Page>

    • Marked as answer by Andrzey Wednesday, October 08, 2014 4:53 AM
    Tuesday, October 07, 2014 7:05 PM
  • Your advices have helped!

    I simply changed a path to the image from Assets\image.png to Assets/image.png and it works.

    спасибо ;-)


    Andrzej

    Wednesday, October 08, 2014 4:53 AM