如何在LongListSelector中包装ItemsPanel?

Ser*_*lyi 12 xaml wrappanel windows-phone-7 windows-phone longlistselector

我正在使用listbox和wrappanel来显示数据.

例如:

    <ListBox ItemTemplate="{StaticResource ItemTemplateListBoxAnimation}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <toolkit:WrapPanel ItemHeight="150" ItemWidth="150">
                </toolkit:WrapPanel>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>

    <DataTemplate x:Key="ItemTemplateListBoxAnimation">
        <Grid Width="130" Height="130">
            <Image Source="{Binding Image}"/>
        </Grid>
    </DataTemplate>
Run Code Online (Sandbox Code Playgroud)

它看起来像:

在此输入图像描述

现在我需要使用LongListSelector和分组结果:

    <toolkit:LongListSelector ItemTemplate="{StaticResource ItemTemplateListBoxAnimation}">
        <toolkit:LongListSelector.GroupItemsPanel>
            <ItemsPanelTemplate>
                <toolkit:WrapPanel/>
            </ItemsPanelTemplate>
        </toolkit:LongListSelector.GroupItemsPanel>
    </toolkit:LongListSelector>
Run Code Online (Sandbox Code Playgroud)

但它看起来像:

在此输入图像描述

我需要得到:

在此输入图像描述

你的假设?谢谢

cod*_*lla 5

问题是,该GroupItemsPanel属性不改变ItemsPanel主列表的,而是ItemsPanel该组头的,因为在这里可以看到(从图像http://www.windowsphonegeek.com/articles/wp7-longlistselector-in-depth --part2-data-binding-scenarios):

组头包裹

不幸的是,WP工具包似乎没有公开ItemsPanel你想要的,所以你必须修改工具包源来获得你想要的行为.

  1. 从这里获取源代码:https://phone.codeplex.com/SourceControl/changeset/view/80797

  2. 解压缩,在Visual Studio中打开Microsoft.Phone.Controls.Toolkit.WP7.sln解决方案.

  3. 在Microsoft.Phone.Controls.Toolkit.WP7项目下,打开Themes/Generic.xaml

  4. 向下滚动到Style适用的目标LongListSelector(TargetType ="controls:LongListSelector")

  5. 更改TemplatedListBox.ItemsPanelWrapPanel

                    <primitives:TemplatedListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <controls:WrapPanel/>
                        </ItemsPanelTemplate>
                    </primitives:TemplatedListBox.ItemsPanel>
    
    Run Code Online (Sandbox Code Playgroud)
  6. 重建并引用新的dll,你的项目应该适当包装!