locked
Change Background Image in Pivot Control Programmatically. RRS feed

  • General discussion

  • Hello,

    What is the best way to change the background image in a Pivot control (or the entire app) programmatically (e.g. though the push of a button in the app)?  I have searched online and tried a number of examples, but none seem to work correctly.

    Thank you in advance.
    Thursday, June 2, 2011 9:49 PM

All replies

  • Normally, a Pivot Control doesn't have an image as a Background. Are you mixing it with the Panorama control?
    Thursday, June 2, 2011 11:04 PM
  • There are a few ways to set a background image in a Pivot. You can set an ImageBrush as the Background of either LayoutRoot or the Pivot, or you can simply put an Image control behind a Pivot with transparent background. You can programmatically change the image by updating the image source. I can advise further if you post the xaml for how you set up your background image.
    Friday, June 3, 2011 2:20 AM
  • I have the background for the Pivot control setup as an ImageBrush.  Not sure how to change this programmatically, however.

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">

    <Grid.Background>
    <ImageBrush ImageSource="/TestWindowsPhoneApplication;component/images/backgrounds/1.png" />
    </Grid.Background>
    Monday, June 6, 2011 8:55 PM
  • Give your ImageBrush a name:
    <Grid.Background> 
    <ImageBrush x:Name="ibBack" ImageSource="/TestWindowsPhoneApplication;component/images/backgrounds/1.png" /> 
    </Grid.Background> 

    Then you can access it from the code-behind by:

    BitmapImage bmp = new BitmapImage(new Uri("newImage.jpg", UriKind.Relative));
    ibBack.ImageSource = bmp;
    Monday, June 6, 2011 9:24 PM