locked
Starting a FlipView with a specific selected item RRS feed

  • Question

  • I have pictures showing in a view, and then upon selection of a picture in that first view, I show a second view that has a FlipView of those same pictures.  I'm trying to start that second view off with the FlipView showing the picture chosen from the first list.  I'm trying this with an MVVM pattern, using a binding for the FlipView.ItemsSource. 

    I first assumed that the FlipView, since it's bound to an ICollectionView, would automatically show the correct picture in the list, based on the ICV.CurrentItem.  Doesn't work.  Next, I tried setting FlipView.SelectedItem via binding to a VM property that had the item selected. Doesn't work.  Now I've even tried setting the Flipper.SelectedIndex in code behind, and that doesnt work.

    Has anybody successfully created a FlipView that starts off showing anything OTHER THAN the first item in the collection?

    I *think* I've saw some apps at BUILD do this, but can't find any in the SDK samples that work like this.

     

    Thursday, September 29, 2011 9:34 PM

Answers

  • There is an active bug on this.  One thing you can do is set the SelectedItem in the LayoutUpdated.   For the sample I showed at Build, right before showing the FlipView, I set the FlipView selected item and then set a flag indicating the need to set the initial item (_updateFV in the code below).  Then I show the FlipView and set the selected item (in the code below, fvc is the FlipView).

            fvc.LayoutUpdated += (o, args) =>
            {
              // Temp update to address FlipView issue
              if (_updateFV == true)
              {
                _updateFV = false;
                var si = fvc.SelectedItem;
                fvc.SelectedItem = null;
                fvc.SelectedItem = si;
              }
            };
    
    Joe

    Thursday, September 29, 2011 9:39 PM

All replies

  • There is an active bug on this.  One thing you can do is set the SelectedItem in the LayoutUpdated.   For the sample I showed at Build, right before showing the FlipView, I set the FlipView selected item and then set a flag indicating the need to set the initial item (_updateFV in the code below).  Then I show the FlipView and set the selected item (in the code below, fvc is the FlipView).

            fvc.LayoutUpdated += (o, args) =>
            {
              // Temp update to address FlipView issue
              if (_updateFV == true)
              {
                _updateFV = false;
                var si = fvc.SelectedItem;
                fvc.SelectedItem = null;
                fvc.SelectedItem = si;
              }
            };
    
    Joe

    Thursday, September 29, 2011 9:39 PM
  • Thanks Joe for the quick reply.

    This did not quite work for me.  It's close...

    I'm binding the FlipView to an ICollectionView (in a VM), which in my navigation logic have called icv.MoveCurrentTo().  When this Flipper LayoutUpdated gets fired, the SelectedItem is not correct.  (Might be a timing/dispatcher issue here - will try to confirm this).

    So using your code, I got it to work, but had to add a "SelectedItem" property on my VM, to be used in the last line in your if block to set the Flipper.SelectedItem to.  Then it works.

    Thanks!

    Friday, September 30, 2011 1:36 AM
  • Am also having this issue where I'm trying to set the FlipView.SelectedItem and having no luck. I'm clicking through from another page and need to pass the e.Param to be the FlipView. Any solutions would be greatly appreciated.

    techAU http://techAU.tv

    Monday, April 16, 2012 10:16 AM
  • When fvc.SelectedItem = null is called, it throws "NotImplementedException". is it not there in CP?

    Scenario is:

    I'm assigning VirtualizedVector returned from the GetVirtualizedFilesVector to FlipView's CollectionViewSource, GridView is populated by using the same vector when item is clicked, getting GridView.cvs.Source and assign it to FlipView's collection view source, it displays first item and selecting next item from flilpview throws exception.  

    Thanks


    CAT


    Thursday, April 26, 2012 8:07 PM
  • Thanks Joe,

    Was losing my mind on this one, the workaround worked. Odd thing was it seemed like it was a matter of timing. If I was doing quick operations the SelectedItems set would actually succeed. Once I started writing operations that would take more time that's when it started to not work. It sounds like its a race condition kind of bug to me. Hope this gets fixed soon. 


    Marc
    • Edited by marc.net Tuesday, August 7, 2012 5:57 AM
    Tuesday, August 7, 2012 5:56 AM
  • Is this still a bug?

    I'm using the RTM bits and it seems to still be a problem.


    Jeff Fattic

    Thursday, November 1, 2012 8:10 PM