如何动态添加枢轴项并将图像添加到每个枢轴项? [英] How to dynamically add pivot item and add Image to each pivot item?

查看:25
本文介绍了如何动态添加枢轴项并将图像添加到每个枢轴项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像 URL 数组.我想为每个图像 URL 动态添加 Pivot 项,并向每个枢轴项添加一个图像框以显示图像.我该如何继续?请帮忙.

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.

感谢和问候

旅行

推荐答案

这不是推荐的方法.改用数据绑定.

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

制作ObservableCollection类型的arrayFeed,将其分配给mainPivotItemsSource并使用ItemTemplate 用于自定义您的项目 UI.

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;

XAML:

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

--编辑--

对于您的评论,

通常,在 Silverlight/WPF 中进行数据绑定时,最好使用 ObservableCollection.ObservableCollection 实现了 INotifyCollectionChanged 接口.每当向 ObservableCollection 添加/删除项目时,通知 UI 元素很有帮助.这样 UI 可以自行更新.

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.

这篇关于如何动态添加枢轴项并将图像添加到每个枢轴项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆