2013-11-27 54 views
0

幾個小時後,我嘗試從WP工具包中更改我的LongListMultiSelector,以便像下面截圖(來自Panorama Sample)一樣水平顯示其項目。LongListMultiSelector的水平項目

http://i.imgur.com/HGHPOsq.png

我甚至嘗試與改變它的模板,但沒有獨到之處影響。

非常感謝您的幫助。

+0

那麼你如何向我們展示你嘗試過的東西? – gleng

+0

我當然不知道該向你展示什麼,因爲只有我獲得的東西是水平的,但是隻有一行。 你知道我想要具有與標準LongListMultiSelector所提供的效果完全相同的效果,但採用水平方式。 我甚至不知道是否可能,因爲我看到StackOverflow與ListListSelector相關的一些問題,從中我明白它只能用於ListBox(但在這裏我將失去我期望的行爲 - 多選。 當然,然後我也無法以我需要的方式顯示元素列表。簡單,水平的StackPanel不是我想要的。 –

回答

0

好的。我終於做到了。如果有人會有同樣的問題,這是我的解決方案。

我總是儘量避免通過代碼背後的方式解決WP中的佈局問題,但特別我這樣做。

我的XAML:

<Grid Margin="10 -30 0 0" Name="GridWithLLMS"> 
    <toolkit:LongListMultiSelector LayoutMode="Grid" 
     ItemsSource="{Binding Items}" 
     GridCellSize="255,190" 
     toolkit:TiltEffect.IsTiltEnabled="True" 
     EnforceIsSelectionEnabled="True" 
     Margin="0" 
    /> 
</Grid> 

我的代碼:

public AddNewTrainingPage() 
{ 
    InitializeComponent(); 

    SetWidthOfGridWithExercisesDependingOnQuantityOfItems(); 
    DataContext = App.Db; 
} 

private void SetWidthOfGridWithExercisesDependingOnQuantityOfItems() 
{ 
    ExercisesListGrid.Width = ((App.Db.Items.Count/3) + 1) * 270; 
} 

其中:

  • 3是行我想有
  • 255的數量是1 寬度LongListM ultiSelectorItem(+潛在邊緣寬度)

當然,我認爲我的LongListMultiSelector的項目將不會改變。如果你想使它與動態元素集合一起工作,你應該將LongListMultiSelector的寬度綁定到你的ViewModel中你的集合項的數量的屬性。

1

檢查了這一點

http://www.geekchamp.com/articles/wp7-longlistselector-in-depth--part2-data-binding-scenarios

在最後的代碼片段會有所幫助。

<toolkit:LongListSelector.GroupItemsPanel> 
    <ItemsPanelTemplate> 
     <toolkit:WrapPanel/> 
    </ItemsPanelTemplate> 
</toolkit:LongListSelector.GroupItemsPanel> 
+0

感謝您的回答。 不幸的是,我使用WP8和您發送的文章是關於WP7。不知道WP7和WP8的區別,但是: 1.在WP8中,我使用''而不是''來使用LongListSelector。 2.從**工具箱編輯LongListMultiSelector的模板**我需要編輯LongL istSelector in LongListMultiSelector 我沒有從''訪問屬性'GroupItemsPanel'的LongListSelector屬性' –