2014-10-27 95 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