简体   繁体   English

在WP8上刷新PivotItem的DataContext

[英]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). 我正在使用一个图像查看器,该图像查看器在pivo控件(主要是从Internet下载的gif)中显示图像。 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: 为此,基于此想法,我使用了3个PivotItems,其中活动项包含当前图像,其他两个包含下一个和上一个:

Endless Pivot control 无尽的枢轴控制

On each SelectionChanged event I want update the pages. 在每个SelectionChanged事件上,我要更新页面。 But how would you update the datacontexts of the PivotItems. 但是,您将如何更新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). 然后将每个数据透视表项绑定到其各自的ViewModel,并在SelectedPivotIndex的设置器中进行任何所需的操作(该绑定器绑定到数据透视表的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). 然后由您决定根据用户的移动方式(向左或向右)在每个枢轴内显示什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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