我正在尝试使用XAML C# Grouped GridView sample使我的SemanticZoom在XAML C#Windows 8应用中运行。问题是,由于某种原因,它显示正确的标题(在这种情况下是类别),但它没有显示标题下的所有项目(它只显示每个项目,当我在其中一些项目中最多有6个项目时)。
这是SemanticZoom的XAML代码(请注意,为了简洁起见,我省略了ZoomedOutView,因为它运行良好):
<SemanticZoom x:Name="boardZoom" Height="626" Margin="10,132,10,0" VerticalAlignment="Top">
<SemanticZoom.ZoomedInView>
<GridView IsSwipeEnabled="True" x:Name="ItemsGridView" Tapped="Tapped" ItemsSource="{Binding Source={StaticResource cvs2}}" SelectionChanged="selChanged">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="10,10,0,0"
HorizontalAlignment="Left" VerticalAlignment="Stretch">
<Image Source="{Binding Thumbnail}"></Image>
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" Width="500"
FontFamily="Global User Interface" FontSize="40" VerticalAlignment="Top" />
<TextBlock Text="{Binding pinNumber}" x:Name="PinNum" Visibility="Collapsed"></TextBlock>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text='{Binding Key}' Foreground="White" Margin="5" FontSize="20" FontFamily="Segoe UI Light" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<StackPanel Orientation="Vertical">
<ContentPresenter Content="{TemplateBinding Content}" />
<ItemsControl x:Name="ItemsControl" ItemsSource="{Binding GroupItems}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="5" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" MaximumRowsOrColumns="1" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</SemanticZoom.ZoomedInView>
和启动应用程序时调用的Refresh()C#函数:
System.Collections.ObjectModel.ObservableCollection<SemanticZoomed> finalSource = new System.Collections.ObjectModel.ObservableCollection<SemanticZoomed>();
public async Task<bool> Refresh()
{
var Pins = await pinTable.ReadAsync(); //pinTable is an Azure Mobile Services table
List<string> categoriesMixed = new List<string>();
if (Pins.ToArray().Length < 1)
{
//adds a new "Welcome" pin to the table, taken out for brevity
}
foreach (pin nowPin in Pins)
{
SemanticZoomed toAdd = new SemanticZoomed();
toAdd.Category = nowPin.category;
toAdd.pinNumber = nowPin.Id.ToString();
toAdd.Title = nowPin.name;
categoriesMixed.Add(nowPin.category);
finalSource.Add(toAdd);
}
List<GroupPinList<object>> groups = new List<GroupPinList<object>>();
var query = from nowPin in finalSource
orderby ((SemanticZoomed)nowPin).Category
group nowPin by ((SemanticZoomed)nowPin).Category into g
select new { GroupName = g.Key, Items = g };
foreach (var g in query)
{
GroupPinList<object> info = new GroupPinList<object>();
info.Key = g.GroupName;
foreach (var item in g.Items)
{
info.Add(item);
}
groups.Add(info);
}
cvs2.Source = groups;
(boardZoom.ZoomedOutView as ListViewBase).ItemsSource = cvs2.View.CollectionGroups;
return true;
}
以下是groups变量的外观截图,以及生成的SemanticZoom显示的内容:
群组变量:
groups变量中的“Welcome”类别(它正确地显示了它的6个项目,以及错误“无法获取字段'imgSrc'的值,因为有关包含类的信息不可用”imgSrc旁边,它消失了下面的cvs2):
cvs2(它显示欢迎类别下的6个不同项目):
最后,结果显示:
我对“欢迎”类别中的其他引脚的位置感到茫然。我错过了XAML代码中的某些内容吗?任何帮助将不胜感激:))
答案 0 :(得分:1)
我有同样的问题。这解决了pb。
在SemanticZoom.ZoomedInView中替换
<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" MaximumRowsOrColumns="1" />
</ItemsPanelTemplate>
通过
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
答案 1 :(得分:0)
我想我知道问题出在哪里 - 如果您在组后以编程方式向GridView添加项目,则会发生这种情况。这里发生的是当你将第一组包含n个项目添加到GridView源时,然后保留数字n,并且对于之后添加的每个组,它显示不超过n个项目,即使有更多项目。
因此,如果您在集合中有5个组以及2,4,1,5,3项,则将空ObservableCollection指定为GridView的ItemSource,然后将这些组添加到ObservableCollection中,您将只看到2 ,每组2,1,2,2项。
我不知道为什么会发生这种情况,如果它的功能或错误,但您可以通过首先加载ObservableCollection然后将其作为源分配给GridView来解决它,或者您可以使用某种转换器,这将为每个组返回相同数量的项目。对于编号较小的组,您可以添加假空项并使用不同的DataTemplate隐藏它们。
编辑:我刚刚注意到你已经立刻添加了这个集合,所以问题可能在其他地方。也许你的问题根源是ItemsPanel?
MaximumRowsOrColumns="1"
答案 2 :(得分:0)
you need to use stackpanel instead of WrapGrip in ItemPanelTemplate
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>