Xaml 显示ListView项目的不同内容相关模板

Xaml 显示ListView项目的不同内容相关模板,xaml,listview,windows-8,datatemplate,Xaml,Listview,Windows 8,Datatemplate,我有这样的数据结构: Post { attachments { }, postText } 要显示这一点,我使用的是ListView <ListView ItemsSource="{Binding Posts}" ItemTemplate="{StaticResource PostTemplate}" Width="Auto" Height="Auto" /> 如何显示用于在附件中呈现所有此

我有这样的数据结构:

Post {
       attachments { }, 
       postText
}
要显示这一点,我使用的是ListView

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

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

作为wpf开发人员,我的第一个答案是使用触发器,但根据本文,windows-8应用程序不能选择触发器。但正如您所看到的,有一种方法可以使用
DataTemplateSelector
实现这一点。我假设您已经为一种附件类型创建了一个模板,并将附件显示为一些
ItemsControl
,因此只需暂停此操作

Attachment {
    type: video,
    url: urlToVideo
}