LongListSelector 控件 在 wp7 和wp8中的不同之處


眾所周知,wp8中的LongListSelector集成到了Rom中。

性能得到了提升,一些api也發生了變化。

在這里總結一下,作為分享,也作為備忘。

參考文獻 Windows Phone 8 XAML LongListSelector

1.首先能一眼看出來的,就是滑動時可以固定的,分組header了。

 這個原來我們都是放一個textblock在那個位置,滑動時根據可視區域所在的項目,然后賦給textblock值。
 現在省事多了。

2. 還有原來很費事才能實現的網格模式。現在通過layoutmode設置了。

 3. 原來的分組模板變成了JumpListStyle,由模板變成了樣式,剛開始這塊弄得有點暈,這讓編輯變得有些不方便了。
為了方便記錄下編輯好的樣式,以后直接拷貝就好了。

 1 <phone:PhoneApplicationPage.Resources>
 2  <phone: JumpListItemBackgroundConverter x:Key="BackgroundConverter"/>
 3        <phone:JumpListItemForegroundConverter x:Key="ForegroundConverter"/>
 4 
 5         <Style x:Key="JumpListStyle" TargetType="phone:LongListSelector">
 6             <Setter Property="LayoutMode" Value="List" />
 7             <Setter Property="Margin" Value="12,12,0,0"/>
 8             <Setter Property="ItemTemplate">
 9                 <Setter.Value>
10                     <DataTemplate>
11                         <Border Background="{Binding Converter={StaticResource BackgroundConverter}}" 
12                             Width="470" 
13                             Height="70" 
14                             Margin="6">
15                             <TextBlock Text="{Binding Key}"
16                                 Foreground="{Binding Converter= {StaticResource ForegroundConverter}}"
17                               Font Family="{StaticResource PhoneFontFamilySemiBold}"
18                                   FontSize="28"
19                                 Padding="2"
20                                 VerticalAlignment="Bottom"/>
21                         </Border>
22                     </DataTemplate>
23                 </Setter.Value>
24             </Setter>
25         </Style>
26 </phone:PhoneApplicationPage.Resources>
View Code

這里有一點值得注意的是 JumpListItemBackgroundConverter and JumpListItemForegroundConverter
如果想設置可點擊或不可點擊的樣式,可以用Disabled="Bisque" Enabled="Aqua"像下面這樣

<phone:JumpListItemBackgroundConverter Disabled="Bisque" Enabled="Aqua" x:Key="BackgroundConverter"/><phone:JumpListItemForegroundConverter Disabled="Azure" Enabled="BlueViolet" x:Key="ForegroundConverter"/>

4.下面是官方給的一些屬性,方法,和事件的變化。

從Windows Phone Toolkit 7.1的屬性中

刪除了

  • BufferSize
  • IsBouncy
  • IsScrolling
  • MaximumFlickVelocity
  • ShowListFooter/ShowListHeader

修改了

Windows Phone Toolkit 7.1

Windows Phone 8 ROM SDK

DisplayAllGroups

Display all groups in the list whether or not they have items. Default is true.

HideEmptyGroups

Hide all groups in the list without items. Default is false.
分組下沒有項的話隱藏分組

GroupItemTemplate

JumpListStyle

IsFlatList

Gets or sets whether the list is flat instead of a group hierarchy. Default is true.

IsGroupingEnabled

Gets or sets whether the list is flat instead of a group hierarchy. Default is false. 分組展示需要開啟此屬性

新增部分

  • GridCellSize
  • LayoutMode LongListSelectorLayoutMode { List, Grid };
  • ManipulationState
public enum ManipulationState
{
    Idle, // nothing is manipulating or animating
    Manipulating, // Gesture is being recognized, finger is down and any delta is received, drag/pan or flick
    Animating //No Gesture is currently happening, but there is some animation happening, like scroll animation or compression animation
} 

 

從Windows Phone Toolkit 7.1的方法中

刪除了

  • AnimateTo(object item)
  • CloseGroupView()
  • DisplayGroupView()
  • GetItemsInView()
  • GetItemsWithContainers(bool onlyItemsInView, bool getContainers)
  • ScrollToGroup(object group)

從Windows Phone Toolkit 7.1的事件中

刪除了

  • StretchingBottom
  • StretchingCompleted
  • StretchingTop

修改了

Windows Phone Toolkit 7.1

Windows Phone 8 ROM SDK

ScrollingCompleted

ScrollingStarted

ManipulationStateChanged

(coupled with ManipulationState property)兩者合二為一了

Link/Unlink

ItemRealized/ ItemUnrealized

With EventArgs including ItemKind

C#
  1. publicclassItemRealizationEventArgs : EventArgs
  2. {
  3.     ///<summary>
  4.     /// The ContentPresenter which is displaying the item.
  5.     ///</summary>
  6.     publicContentPresenter Container { get; }
  7.  
  8.     ///<summary>
  9.     /// Gets the kind of item that is realized
  10.     ///</summary>
  11.     publicLongListSelectorItemKind ItemKind { get; }
  12.  
  13. }
  14. ///<summary>
  15. /// Different kinds of items that exists in LongListSelector
  16. ///</summary>

 

可以看到,其實變化挺大的。

wp 8 sdk中的LLS性能 明顯要比之前提高了不少。

當然 panorama,和pivot的性能也有了很大的提高,尤其是panorama的數據加載。

最后微軟建議我們用longlistselector代替ListBox(這種說法幾乎到處可見)

那么到底LLS比ListBox好在那里呢?請關注我的下篇文章。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM