2014-10-27 74 views
1

我想创建一个可滚动的网格,在我的应用程序中,我有一个垂直滚动的文本项目如下所示的列表框。WP水平滚动网格选择

<ListBox x:Name="selectionList" Margin="49,0,11,0" Padding="20,20,0,0"  SelectionChanged="AlbumList_SelectionChanged" ItemsSource="{Binding ''}" Background="{x:Null}"  Height="606" VerticalAlignment="Top" Width="420"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <TextBlock Text="{Binding SlectionTitle}" FontSize="22" Margin="0,0,0,10" FontFamily="{StaticResource hevel}" Foreground="#FF99FFFF"/> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
</ListBox> 

所以我改变了TextBlock的这个

<Border x:Name="Selection_List_Image" BorderBrush="#FFC4C3C3" BorderThickness="8" HorizontalAlignment="Left" Height="198" Margin="18,24,0,5" VerticalAlignment="Center" Width="199" CornerRadius="12" RenderTransformOrigin="0.5,0.5" Padding="0"> 
         <Border.Background> 
          <ImageBrush Stretch="Fill" ImageSource="{Binding SelectionArt}"/> 
         </Border.Background> 
        </Border> 

这是罚款单垂直滚动列表。我试图获得一个网格,例如永久4图像高,自动宽,所以如果有4个图像,它显示了一列4如果有8个图像,它显示2列4等等

我已经试过了这个例子 WP7 - issues with Horizontal scrolling Listbox

,但它只是不停列表垂直滚动和水平

任何建议,感谢

//解决

谢谢你,我最后不得不通过改变<ItemsPanelTemplate><WrapGrid>Orientation设置为垂直和MaximumRowsOrColumns设置为使用例如链接aswel

 <ListBox x:Name="AlbumList" Margin="49,0,11,0" ScrollViewer.HorizontalScrollBarVisibility="Auto" 
ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionChanged="AlbumList_SelectionChanged" ItemsSource="{Binding ''}" Background="{x:Null}" Height="748" > 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <toolkit:WrapPanel Orientation="Vertical" ></toolkit:WrapPanel> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <Border x:Name="Album_List_Image" BorderBrush="#FFC4C3C3" BorderThickness="8" HorizontalAlignment="Left" Height="152" Margin="18,24,0,5" VerticalAlignment="Center" CornerRadius="12" RenderTransformOrigin="0.5,0.5" Padding="0" Width="152"> 
         <Border.Background> 
          <ImageBrush Stretch="Fill" ImageSource="{Binding AlbumArt}"/> 
         </Border.Background> 
        </Border> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 

回答

1

如果你正在做WP8.1运行时,你可以很容易地做到这一点,以4像这样,

MSDN WrapGrid(实际上他们做你想要什么的例子..但在其它方向)

<ListBox> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapGrid Orientation="Vertical" MaximumRowsOrColumns="4"/> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <!-- your data template --> 
     </DataTemplate> 
    </ListBox.ItemTemplate>  
</ListBox> 

如果你用WP8.0 + SL做这个,那么它会稍微有些困难。您需要在Windows Phone工具包,并使用<WrapPanel>代替,但你会需要一些数据绑定值(或硬编码...根据您的视图模型如何松动是)

<ListBox x:Name="myListBox" Height="412"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <toolkit:WrapPanel Orientation="Vertical" ItemHeight="100" ItemWidth="100"></toolkit:WrapPanel> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <!-- your data template --> 
     </DataTemplate> 
    </ListBox.ItemTemplate>     
</ListBox> 

在这个例子中,我硬编码的每个项目为100x100,我硬编码高度为412,从而使其在垂直方向上有4个项目。

如果您选择这样做,可以将数据绑定HeightItemHeightItemWidth