>更新 2012/9/17:重述问题并添加了娱乐步骤
我正在尝试将 WrapGrid 样式的图像库添加到 ItemDetailPage。 到目前为止,我发现实现此目的的唯一解决方案是创建组样式并使用 DataTemplate 选择器。 在详细信息页面上执行此操作似乎有些矫枉过正,因为我需要为页面上的每一列创建一个类。
我试图解决这个问题,如下所示,但 GridView 独立于我的滚动查看器滚动,这是不可接受的。
要重新创建,请从 VS 中的默认网格应用程序开始:
将此属性添加到示例数据项
// Add to SampleDataItem TODO: replace int with image url strings
private List<int> _subItems = null;
public List<int> SubItems
{
get
{
if (_subItems == null)
{
_subItems = new List<int>();
for (int i = 0; i < 50; i++)
this._subItems.Add(i);
}
return this._subItems;
}
set { this.SetProperty(ref this._subItems, value); }
}
in ItemDetailPage.xaml 替换 ScrollViewer 中的 RichTextColumns:
<!--Fixed column layout, replaces RichTextColumns from template-->
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="800"/>
<ColumnDefinition Width="1400"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="{Binding Title}"/>
<Image x:Name="image" MaxHeight="480" Margin="0,20,0,10" Stretch="Uniform" Source="{Binding Image}"/>
</StackPanel>
<GridView ScrollViewer.HorizontalScrollMode="Disabled" VerticalAlignment="Top" ItemsSource="{Binding SubItems}" Grid.Column="1" ItemTemplate="{StaticResource GridViewDataTemplate1}" >
</GridView>
</Grid>
最后添加以下数据模板
<DataTemplate x:Key="GridViewDataTemplate1">
<Grid Background="Yellow" Width="200" Height="200"/>
</DataTemplate>
将 GridView 的水平滚动模式设置为 Disabled
来实现此目的
<GridView ScrollViewer.HorizontalScrollMode="Disabled" />
但是,我敦促您在这里考虑最佳方法。如果网格视图与每个网格视图不相关,请在单独的页面上显示它们。如果它们相关,则对一个 GridView 进行分组。您可以使用数据模板选择器以不同的方式设置组项目的样式。