locked
How to add image to FlipView control?

    Question

  • Hi!

    I'm trying to add images to a FlipView control by code, but I only got text showing. What am I doing wrong?
    The first item is using the same path as the second item, but just another color.

    Windows Phone 8.1 (universal app)

        <Grid>
            <FlipView x:Name="flipView" SelectionChanged="FlipView_SelectionChanged"/>
        </Grid>
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                BitmapImage img = new BitmapImage(new Uri(param.Split('#')[0]));
                flipView.Items.Add(img);
                flipView.Items.Add("ms-appx:///Assets/Products/621245_DNAVY.png");
                flipView.Items.Add("Assets/Products/621245_HCORA.png");
                flipView.Items.Add("Assets/Products/621245_Rpink_big.png");
    
            }
    Thanks, Sigurd F


    • Edited by Sigurd F Wednesday, August 27, 2014 8:44 PM
    Wednesday, August 27, 2014 8:43 PM

Answers

  • The BitmapImage is an image source. It doesn't display on its own.

    To display it you need to host it in an Image control:

    Image imgControl = new Image();
    imgControl.Source = img;
    flipView.Items.Add(imgControl);

    • Marked as answer by Sigurd F Thursday, August 28, 2014 8:16 PM
    Wednesday, August 27, 2014 9:05 PM
    Owner

All replies

  • The BitmapImage is an image source. It doesn't display on its own.

    To display it you need to host it in an Image control:

    Image imgControl = new Image();
    imgControl.Source = img;
    flipView.Items.Add(imgControl);

    • Marked as answer by Sigurd F Thursday, August 28, 2014 8:16 PM
    Wednesday, August 27, 2014 9:05 PM
    Owner
  • Thanks a lot :-)

    Regards, Sigurd F

    Thursday, August 28, 2014 8:16 PM