3

我正在尝试使用XAML C# Grouped GridView 示例使我的 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;
}

下面是一些关于组变量的截图,以及生成的 SemanticZoom 显示的内容:

组变量:

组变量

groups 变量中的“欢迎”类别(它正确显示了它的 6 个项目,以及 imgSrc 旁边的错误“无法获取字段 'imgSrc' 的值,因为有关包含类的信息不可用”,它在下面的 cvs2 中消失了) :

欢迎类别

cvs2(它显示了 Welcome 类别下的 6 个不同的项目):

cvs2

最后,它最终显示的内容:

最终结果

我不知道欢迎类别中的其他别针去了哪里。我缺少 XAML 代码中的某些内容吗?任何帮助将非常感激 :)

4

3 回答 3

1

我也有同样的问题 。这解决了 pb 。

在 SemanticZoom.ZoomedInView 替换

<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" MaximumRowsOrColumns="1" />
</ItemsPanelTemplate>

经过

<ItemsPanelTemplate>
         <VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
于 2013-05-08T16:05:47.630 回答
0
you need to use stackpanel instead of  WrapGrip in ItemPanelTemplate

<GridView.ItemsPanel>
           <ItemsPanelTemplate>
               <StackPanel Orientation="Horizontal" />
           </ItemsPanelTemplate>
</GridView.ItemsPanel>
于 2012-10-30T15:11:29.787 回答
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"
于 2012-10-11T07:41:41.010 回答