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

advertisements

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

vaysage


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.

Example:

Code:

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

XAML:

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

--EDIT--

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.