【发布时间】:2016-05-07 21:38:54
【问题描述】:
我在 StackOverflow 上阅读了很多帖子和很多博客条目,但找不到我的问题的有效答案: 我正在开发一个 Windows 10 通用应用程序。我有一个使用项目模板的列表视图。现在我添加了另一个项目模板,并希望设置应用程序启动时使用的模板。不用逐项做,模板要全部加完。
<Page.Resources>
<DataTemplate x:Key="DataTemplate1">
(...)
</DataTemplate>
<DataTemplate x:Key="DataTemplate2">
(...)
</DataTemplate>
</Page.Resources>
<ListView
x:Name="itemListView"
AutomationProperties.AutomationId="ItemsListView"
AutomationProperties.Name="Items"
TabIndex="1"
Grid.Column="0"
IsSwipeEnabled="False" HorizontalContentAlignment="Stretch"
SelectionChanged="ItemListView_SelectionChanged" IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding FeedItems}" ItemTemplate="{StaticResource DataTemplate1}" Margin="0,60,0,10" Grid.RowSpan="2">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
最简单的方法是什么?我尝试了很多选择,但都没有奏效:-( 非常感谢!
【问题讨论】:
标签: c# xaml listview uwp windows-10-universal