How to Show Previous page selected item in flip view control in another page in windows 8?

StackOverflow https://stackoverflow.com/questions/17715502

  •  03-06-2022
  •  | 
  •  

سؤال

I want to show the grid view selected item in flip view control.The control was placed in another page. Please tell me how to get this?

I tried the below code: Previous Page grid view item click event:

private void PhotoGrid_ItemClick(object sender, ItemClickEventArgs e)
        {
            var itemid = ((flipimage)e.ClickedItem);
            flipimage s = new flipimage() { ImageUrl = itemid.ImageUrl, Title = itemid.Title };
            this.Frame.Navigate(typeof(FlipPage), s);
        }

Second Page :

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //XDocument xdoc = XDocument.Load("XMLFile1.xml");
            //IEnumerable<flipimage> images = from img in xdoc.Descendants("Image") select new flipimage(img.Element("ImageTitle").Value, img.Element("ImageUrl").Value);

            flipimage s = (flipimage)e.Parameter;
           string url =  s.ImageUrl;
           flipviewcontrol.Items.Add(url);

           //flipviewcontrol.DataContext = images;
        }



<FlipView HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="flipviewcontrol" ItemsSource="{Binding}">
            <FlipView.ItemTemplate>
                <DataTemplate>

                    <Image HorizontalAlignment="Left"  Source="{Binding ImageUrl}" Height="762" VerticalAlignment="Top" Width="1360" x:Name="imagecontrol"/>
                </DataTemplate>
            </FlipView.ItemTemplate>

        </FlipView>

Please tell me how to show previuos page images in flip view another page in windows 8?

هل كانت مفيدة؟

المحلول

Hey i have made a standard sample to work with your problem..you are binding your flipview Itemssource to Images ( collection of strings i think in your case ..) so first make a ObservableCollection named Images..like this.in your page.cs( or in your view model if you are using in that case you have to send message to your viewmodel.) like this..

 public ObservableCollection<string> Images { get; set; }

in your page constructor do this..

public BasicPage1()
    {
        this.InitializeComponent();
        Images = new ObservableCollection<string>();


        this.DataContext = this;
    }

and when you navigate to this page just add string url to your collection it will automatically update your flipview..i have taken a predefined string(i think it's fine)

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        //XDocument xdoc = XDocument.Load("XMLFile1.xml");
        //IEnumerable<flipimage> images = from img in xdoc.Descendants("Image") select new flipimage(img.Element("ImageTitle").Value, img.Element("ImageUrl").Value);

        string url = "/Assets/teacher-symbol.png";
        Images.Add(url);
        Images.Add(url);
        Images.Add(url);
        Images.Add(url);
        Images.Add(url);
        Images.Add(url);
      //  flipviewcontrol.Items.Add(url);

        //flipviewcontrol.DataContext = images;
    }

now change your flipview control like this..

<FlipView HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="flipviewcontrol" ItemsSource="{Binding Images}" Grid.Row="1">
        <FlipView.ItemTemplate>
            <DataTemplate>

                <Image HorizontalAlignment="Left"  Source="{Binding}" Height="762" VerticalAlignment="Top" Width="1360" x:Name="imagecontrol"/>
            </DataTemplate>
        </FlipView.ItemTemplate>

    </FlipView>

hope this help..for any query comment below..

for your query..you have to do this..for your other images..

private void flipviewcontrol_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        string url = "/Assets/usericondash.png";
        Images.Add(url);
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top