Search code examples
c#linqwindows-phonewindows-phone-8.1

Set content of particular Pivot Item


I wrote a Windows Phone 8.1 (WINPRT) App. It contains Pivot, in which pivot items are generated dynamically according to JSON.

For example, when I open Clothing Category Page,>> Summer Wear,Winter Wear etc pivot items are generated dynamically.

Now I am clicking the button to load more items in GridView (ObservableCollection) and it is shown on currently selected PivotItem.

(MainPagePivot.SelectedItem as PivotItem).Content = StatusGridObject;

How to add these items to some other pivot item and not the selected one. example i am on pivotitem having index 0, how to add data to pivot item having index 4? Any linq query?? I dont want to use MainPagePivot.SelectedItem but some other pivot item


Solution

  • I think you can do something like this:

    ((PivotItem)MainPagePivot.Items[index]).Content = StatusGridObject;
    

    Of course, thanks to linq you can also use something like .Where() or .Any() on MainPagePivot.Items

    example with linq:

    ((PivotItem)MainPagePivot.Items.First(p => p.Name == "PivotItemFour")).Content = StatusGridObject;
    

    Let me know if it works!