XAML分组的GridView /语义缩放无法显示所有的孩子?(XAML grouped GridV

2019-08-01 08:03发布

我试图使用XAML C#分组的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>

并刷新()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显示了一些截图:

组变量:

在组变量“欢迎”类别(它正确地显示了它的6个项目,并且还旁边IMGSRC,这在下面CVS2消失错误“因为关于包含类信息不可用无法提取字段‘IMGSRC’的值”) :

CVS2(它显示在欢迎类别中的6个不同的项目):

最后,它最终会显示:

我手足无措,到在欢迎类别的其他引脚去了。 有东西在我失踪的XAML代码? 任何帮助将非常感激 :)

Answer 1:

我想我知道哪来的问题 - 出现这种情况,如果你组后添加项目到GridView编程组。 当你与n项添加第一个组到GridView源,然后数n保持和后来加入的各组也没有显示出N多的项目,即使有更多的项目会发生什么事在这里。

所以,如果你有5组收集与2,4,1,5,3项,分配空的ObservableCollection作为GridView控件的的ItemSource,然后你的foreach添加这些组到的ObservableCollection,你只会看到2,2, 1,2,2项各组英寸

我不知道为什么会这样,如果它的功能还是一个bug,但你可以通过先加载的ObservableCollection,然后将其作为源分配到GridView解决它,或者你可以使用某种转换器,这将返回项目中的每一组相同的号码。 对于较小的组数你再添加虚假空项目,并使用不同的DataTemplate隐藏起来。

编辑:我刚刚注意到你已经将收集一次,所以这个问题可能是在其他地方。 也许你根本您的问题是这ItemsPanel?

MaximumRowsOrColumns="1"


Answer 2:

我也有同样的问题 。 而这在解决PB。

在SemanticZoom.ZoomedInView更换

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

通过

<ItemsPanelTemplate>
         <VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>


Answer 3:

you need to use stackpanel instead of  WrapGrip in ItemPanelTemplate

<GridView.ItemsPanel>
           <ItemsPanelTemplate>
               <StackPanel Orientation="Horizontal" />
           </ItemsPanelTemplate>
</GridView.ItemsPanel>


文章来源: XAML grouped GridView/Semantic Zoom not displaying all children?