【发布时间】:2017-03-01 14:03:28
【问题描述】:
我正在开发一个 UWP 应用程序,尝试使用 GridView 而不是 HubSection 从平台示例中实现 Transform3DAnimations。除了获取GridViewItem 之外,我已经弄清楚了。下面的代码是从上下文中的示例到 hubsection。
private void UpdateRandomSection()
{
// Updating the section triggers a cool animation!
// See SectionView.xaml and SectionView.xaml.cs
var sectionsInView = HeadlinesHub.SectionsInView;
var sectionsCount = sectionsInView.Count;
if (sectionsCount > 0)
{
var sectionToUpdate = sectionsInView[_random.Next(sectionsCount)];
sectionToUpdate.DataContext = new HeroArticlesViewModel();
}
}
我正在尝试获取GridViewItem,但我无法获取GridViewItem,它总是返回GridViewItem 的数据模型。如何从GridView 获取GridViewItem?我的代码如下:
private Random InAppLiveTileRandomTileNumberGenerator;
private void UpdateRandomSection()
{
var sectionsInView = AllDevicesGridView.Items;
var sectionsCount = sectionsInView.Count;
if (sectionsCount > 0)
{
var sectionToUpdate = (GridViewItem)AllDevicesGridView.Items[InAppLiveTileRandomTileNumberGenerator.Next(sectionsCount)]; //Invalid Cast exception here
sectionToUpdate.DataContext = new InappLiveTileViewModelModel();
}
}
【问题讨论】: