12

Estoy usando listbox y wrappanel para mostrar datos.Cómo envolver ItemsPanel en LongListSelector?

Por ejemplo:

<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> 

ella es mirada como:

enter image description here

Ahora necesito utilizar LongListSelector y el resultado de agrupación:

<toolkit:LongListSelector ItemTemplate="{StaticResource ItemTemplateListBoxAnimation}"> 
     <toolkit:LongListSelector.GroupItemsPanel> 
      <ItemsPanelTemplate> 
       <toolkit:WrapPanel/> 
      </ItemsPanelTemplate> 
     </toolkit:LongListSelector.GroupItemsPanel> 
    </toolkit:LongListSelector> 

Pero se ve como:

enter image description here

Necesito llegar:

enter image description here

Sus suposiciones? Gracias

Respuesta

5

La cuestión es que la propiedad GroupItemsPanel no está cambiando la ItemsPanel de la lista principal, sino más bien la ItemsPanel de los encabezados de grupo, como se puede ver aquí (imagen a partir de http://www.windowsphonegeek.com/articles/wp7-longlistselector-in-depth--part2-data-binding-scenarios):

group headers wrapped

Desafortunadamente no parece que el conjunto de herramientas WP para exponer la ItemsPanel que desea, por lo que tendrá que modificar la fuente conjunto de herramientas para obtener el comportamiento que desea.

  1. obtener el código fuente desde aquí: https://phone.codeplex.com/SourceControl/changeset/view/80797

  2. Descomprimir, abren la solución Microsoft.Phone.Controls.Toolkit.WP7.sln en Visual Studio.

  3. el marco del proyecto Microsoft.Phone.Controls.Toolkit.WP7, Temas abiertos/Generic.xaml

  4. Vaya a la Style que se aplica a LongListSelector (TargetType = "controles: LongListSelector")

  5. Cambiar el TemplatedListBox.ItemsPanel a un WrapPanel

       <primitives:TemplatedListBox.ItemsPanel> 
            <ItemsPanelTemplate> 
             <controls:WrapPanel/> 
            </ItemsPanelTemplate> 
           </primitives:TemplatedListBox.ItemsPanel> 
    
  6. Reconstruir y hacer referencia a la nueva DLL, sus artículos sh ¡debería envolverse apropiadamente!

+0

Excelente respuesta! Aunque es un poco raro para mí, me quedaré con ListBox por ahora. – MEMark

3

Puede evitarla usando estilo personalizado

<toolkit:LongListSelector 
         Background="{StaticResource FCBackground}" 
         HorizontalContentAlignment="Stretch" 
         ItemsSource="{Binding NowShowingEvents}" 
         ItemTemplate="{StaticResource EventsListMediumItemTemplate}" 
         IsFlatList="True" 
         Style="{StaticResource LongListSelectorStyleCustom}" 
           > 

        </toolkit:LongListSelector> 


    <Style x:Key="LongListSelectorStyleCustom" TargetType="toolkit:LongListSelector"> 
     <Setter Property="Background" Value="{StaticResource PhoneBackgroundBrush}"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="toolkit:LongListSelector"> 
        <toolkitPrimitives:TemplatedListBox x:Name="TemplatedListBox" Background="{TemplateBinding Background}"> 
         <toolkitPrimitives:TemplatedListBox.ItemContainerStyle> 
          <Style TargetType="ListBoxItem"> 
           <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
          </Style> 

         </toolkitPrimitives:TemplatedListBox.ItemContainerStyle> 
         <toolkitPrimitives:TemplatedListBox.ItemsPanel> 
          <ItemsPanelTemplate> 
           <toolkit:WrapPanel Margin="24,0,12,24"/> 
          </ItemsPanelTemplate> 
         </toolkitPrimitives:TemplatedListBox.ItemsPanel> 
        </toolkitPrimitives:TemplatedListBox> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
Cuestiones relacionadas