zoukankan      html  css  js  c++  java
  • Wp8—LongListSelector控件使用

                  其实从去年后半年起,自己就开始学习windows phone 8 的开发,主要是自己感兴趣同时我也很看好这个系统(现在还是感觉自己认识的有点晚了)。工作日的话基本很忙,所以当时想到然的认为用晚上时间可以看资料,但是实际到晚上以后已经没心情看电脑了,有一些日子是强迫自己学习的,可是到现在看来已经忘了很多,当然周末也用上一些了(我认为程序员应该利用周末时间多去外面转转,毕竟有时候周末还加班什么的,而不是依旧盯着电脑玩游戏,这样的话不仅对身体而言,还有对自己紧张的大脑都起不了真正休息的效果。)。不过还好应该算有些进步了吧,如果顺利的话,过段时间就能发布自己的第一个window phone8 app了。当然这其中也学习一些新的知识,我想有时间慢慢总结写出了,这样不仅对自己是个巩固,对想学习的人希望也是个帮助。

                 windows phone 系统界面,是扁平化的磁贴 组成,个性十足,个人超级喜欢(我顺便也把自己的博客主题风格也改成了简洁版,希望大家吐槽哦)。 其中用来显示列表信息的控件有listbox和LongListSelector两个,其中longlistselector控件功能强大,展示效果也很符合windows phone 风格。所以我想最先拿出来练练手(现学现卖),下面是就着自己做的一个实例展开的。

      xmal代码:

     <phone:LongListSelector x:Name="LLSContacts" Margin="480,20,480,0"  Width="480"  LayoutMode="List" IsGroupingEnabled="true" HideEmptyGroups ="true" Padding="0,0,0,10" >
                                <!--head-->
                                <phone:LongListSelector.GroupHeaderTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="12,0,0,0" Width="432" Height="90" >
                                            <Border Background="Transparent" Margin="0" Padding="0,0,0,10"  >
                                                <Border Background="#008AFF" BorderBrush="#008AFF" BorderThickness="2" Width="80" Height="80" HorizontalAlignment="Left" Margin="0" >
                                                    <TextBlock Text="{Binding Key}" FontSize="48" Padding="6" 
                FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="White"/>
                                                </Border>
                                            </Border>
                                        </StackPanel>
                                    </DataTemplate>
                                </phone:LongListSelector.GroupHeaderTemplate>
                                <!--body-->
                                <phone:LongListSelector.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Margin="12,0,0,0" Height="90" Width="432" >
                                    <!--用图像替换矩形-->
                                    <!--<Image  Width="80" Height="80" Source=""/>-->
                                            <Border Width="80" Height="80" CornerRadius="0">
                                                
                                                <Border.Background>
                                                    <ImageBrush Stretch="Fill"  ImageSource="{Binding Images}"/>
                                                </Border.Background>
                                            </Border>
                                            <StackPanel Width="311" Margin="8,0,0,0" >
                                                <TextBlock Text="{Binding DisplayName}" TextWrapping="Wrap" Margin="10,5,10,0" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="{StaticResource PhoneFontSizeLarge}" Foreground="#FF555555" />
                                                <TextBlock Text="{Binding PhoneNumbers}" TextWrapping="Wrap" Margin="10,5,10,0" Style="{StaticResource PhoneTextSubtleStyle}" Foreground="#FF9B9A9A" />
                                            </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                                </phone:LongListSelector.ItemTemplate>
                                <phone:LongListSelector.JumpListStyle>
                                    <Style   TargetType="phone:LongListSelector">
                                        <Setter Property="GridCellSize"  Value="113,113"/>
                                        <Setter Property="LayoutMode" Value="Grid" />
                                        <Setter Property="ItemTemplate">
    
                                            <Setter.Value>
                                                <DataTemplate>
    
                                                    <Border Background="{Binding Converter={StaticResource BackgroundConverter}}" Width="113" Height="113" Margin="6" >
                                                        <TextBlock Text="{Binding Key}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" FontSize="48" Padding="6" 
                   Foreground="{Binding Converter={StaticResource ForegroundConverter}}" VerticalAlignment="Center"/>
                                                    </Border>
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </phone:LongListSelector.JumpListStyle>
                            </phone:LongListSelector>
    View Code


          1.GroupHeaderTemplate:该模板字面上理解为组头部模板,也就是显示列表内容分组的页眉,通常默认列是以你设定分组字段的手字母为依据进行分组,如果是汉字默认是单词拼音的第一个字母,功能上可以理解为组的节点吧。

          2.ItemTemplate:列表项模板,是LongListSelector控件最基本的,里面就是显示动态列表项单行,根据传进来的集合显示一哗啦子。

          3.JumpListStyle:设置跳转列表的样式,在里面设置跳转后节点界面的内容和风格。常用情况是呈现分组选项页,也就是点分组页眉内容跳转到一个只有组头部想内容的页面,用户可选择点击然后定位到列表该分组的地方,方便实用。

          4.StaticResource:静态资源,实际上是为XAML 属性特性提供值的标签扩展,我们可以理解为绑定标签属性的一种语法把。比如 FontFamily="{StaticResource PhoneFontFamilySemiLight}" ,字体为系统内定动态属性,我啥样你就啥样。

          5.还有个地方设置标签属性特殊点,在jumplistStyle中你们可以看到这个Background="{Binding Converter={StaticResource BackgroundConverter}}",这是实际上是设置我们自己定义的样式,对应的resource代码如下

    <phone:PhoneApplicationPage.Resources>
            <phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter" Enabled="#FF008AFF"/>
            <phone:JumpListItemForegroundConverter x:Key="ForegroundConverter" Enabled="White"/>
        </phone:PhoneApplicationPage.Resources>

    前台的代码即是这样,其他也没什么特殊,相信没学过xaml的人也看得懂吧,

           还有一点要注意:如果要实现今天所展示功能,请在LongListSelector中加上 IsGroupingEnabled=“true”和 HideEmptyGroup="true"这两个属性。因为默认情况下不带有的

              后台代码

              后台我直接绑定一个集合到控件既可

     List<AlphaKeyGroup<MyContacts>> DataSource = AlphaKeyGroup<MyContacts>.CreateGroups(ListContact,
                   System.Threading.Thread.CurrentThread.CurrentUICulture,
                   (MyContacts s) => { return s.DisplayName; }, true);
    
                    LLSContacts.ItemsSource = DataSource;
    View Code

             前台对应的{bing=***}即是对象的属性

             展示效果图

                   

       

               最后想说一下,如果有喜欢wp8开发的朋友,请叫上我吧,因为我也一样。目前只是我一个人摸索开发中,中间肯定很累且少不了走弯路,不过我相信以后肯定有更多人参与的,大家一起加油。

  • 相关阅读:
    人为什么会生气 --- 答案是什么?
    职场中我们常犯的8个错误
    职场上最常见的20条错误,犯三条就够致命啦
    C语言,基于单向链表实现,变长动态数据缓冲区(线程安全) ---- 类似java的StringBuffer --- 亲测OK
    门限签名
    基于RSA的实用门限签名算法
    图解密码技术(第3版)-第4章
    各种加密算法比较
    密码那点事儿
    数字签名,我有疑问。
  • 原文地址:https://www.cnblogs.com/Dotaer/p/LongListSelector.html
Copyright © 2011-2022 走看看