How to dynamically add a pivot element and add an image to each pivot element?


I have an array of Image URLS .I want to dynamically add Pivot item for each image Url, and add an image box to each pivot item to display the image .How can i proceed ? Please help.

Thanks and Regards


This is not the recommended approach. Use data-binding instead.

make arrayFeed of type ObservableCollection<Uri>, assign it to ItemsSource of mainPivot and use ItemTemplate to customize your item UI.



ObservableCollection<Uri> arrayFeed = new ObservableCollection<Uri>();
// populate arrayField
mainPivot.ItemsSource = arrayFeed;


<Pivot Name="mainPivot">
            <Image Source="{Binding}" />


For your comment,

Generally, it is a good idea to use ObservableCollection while data-binding in Silverlight/WPF. ObservableCollection implements INotifyCollectionChanged interface. It is helpful for notifying UI elements whenever items are added to/removed from ObservableCollection. That way UI can update itself.