Note that there are some explanatory texts on larger screens.

plurals
  1. POEndless Pivot Control
    text
    copied!<p>I'm trying to use a <code>Pivot</code> control for a calendar type app, where each <code>Pivot</code> view shows some infos about the current day. When the user swipes forward, the next day is shown. I implemented this by adding items to the end of the <code>Pivot</code> Item collection, which works fine.</p> <p>My problem occurs when the user tries to go backward to the previous day. In this case a new item is added at the beginning of the <code>Pivot</code> item collection. Although the adding works, the shown Pivot item is always the wrong one (ie. the newly added item). Setting <code>SelectedItem</code> on the <code>Pivot</code> control doesn't help.</p> <p>I think <code>Pivot</code> might not be the right control for my task, so any help about what view to use or how fix my aforementioned problem with <code>Pivot</code> are highly appreciated.</p> <p>code for my Viewmodel that implements going forward/backward one day. <code>Pages</code> is bound to the Pivot <code>ItemSource</code>.</p> <pre><code>public class TrackDayViewModel : HubViewModelBase { private DateTime _CurrentDay; public DateTime CurrentDay { get { return _CurrentDay; } set { if (value.CompareTo (_CurrentDay) != 0) { _CurrentDay = value; OnPropertyChanged("CurrentDay"); } } } public TrackDayViewModel () { var day = DateTime.Now; CurrentDay = day.Midnight(); Pages.Add(new DayViewModel(CurrentDay.AddDays(-1))); Pages.Add(new DayViewModel(CurrentDay)); Pages.Add(new DayViewModel(CurrentDay.AddDays(1))); SelectedItem = Pages[1]; this.PropertyChanged += (s, e) =&gt; { if (e.PropertyName == "SelectedItem") { var si = SelectedItem as DayViewModel; if (si != null) { var idx = Pages.IndexOf(SelectedItem); if (idx==0) { Pages.Insert(0, new DayViewModel(si.Day.AddDays(-1))); SelectedItem = Pages[1]; } else if (idx == (Pages.Count - 1)) { Pages.Add(new DayViewModel(si.Day.AddDays(1))); } } } }; } } </code></pre> <p>EDIT: Change that solved my problem:</p> <pre><code> this.PropertyChanged += (s, e) =&gt; { if (e.PropertyName == "SelectedItem") { var si = SelectedItem as DayViewModel; if (si != null) { var idx = Pages.IndexOf(SelectedItem); int nextIdx = (idx + 1) % 3; int prevIdx = ((idx - 1)&lt;0) ? 2 : (idx-1); Pages[nextIdx] = new DayViewModel(si.Day.AddDays(1)); Pages[prevIdx] = new DayViewModel(si.Day.AddDays(-1)); } } }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload