简体   繁体   中英

Refreshing PivotItem's DataContext on WP8

I'm working on an image viewer that displays images inside a pivo control (mainly gifs downloaded from the internet). I'd like to make it an "endless" pivot. For that I used 3 PivotItems where the active item contains the current image and the other two contain the next and the previous one based on this idea:

Endless Pivot control

On each SelectionChanged event I want update the pages. But how would you update the datacontexts of the PivotItems. I can't access them from the codebehind, I can only access the Pivot.

You can do this

public class PageViewModel
{
   ViewModel LeftPivot {get; set;}
   ViewModel CurrentPivot {get; set;}
   ViewModel RightPivot {get; set;}

   int SelectedPivotIndex {get; set;}
}

then bind each pivot item to its respective ViewModel and do whatever you want inside the setter of the SelectedPivotIndex (which is TwoWay bound to the Pivot's SelectedIndex). Then it is up to you to figure out what to show inside each pivot depending on how the user moves (left or right).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM