【问题标题】:Show different content-related templates for ListView item为 ListView 项显示不同的内容相关模板
【发布时间】:2012-10-30 09:19:01
【问题描述】:

我有这个数据结构:

Post {
       attachments { }, 
       postText
}

为了显示这个,我使用 ListView

<ListView ItemsSource="{Binding Posts}"
          ItemTemplate="{StaticResource PostTemplate}"
          Width="Auto"
          Height="Auto" />

问题是,当我尝试在每个帖子中显示附件列表时。 每个附件都是一些类型内容(视频/音频/图像)的简单类型链接

Attachment {
    type: video,
    url: urlToVideo
}

如何显示基于上下文的模板以在附件中呈现所有类型的内容?

【问题讨论】:

    标签: xaml listview windows-8 datatemplate


    【解决方案1】:

    作为 wpf 开发人员,我的第一个答案是使用触发器,但根据这篇文章,this 不是 windows-8 应用程序的选项。但正如您所见,有一种方法可以使用DataTemplateSelector。我假设您已经为一种附件类型创建了一个模板,并且您将附件显示为一些ItemsControl,所以只需将此article 放假。

    【讨论】:

      猜你喜欢
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多