微软在Wp8中集成了LongListSelector, 但是该控件在ViewModel中不能实现的SelectdeItem双向绑定,因为其不是DependencyProperty没办法只能实现扩展!

1.实现LongListSelector的扩展ExtendedSelector

  public enum PositionOnAdd
{
Top,
Default,
NewItem
}
public class ExtendedSelector : LongListSelector
{
public static readonly DependencyProperty SelectedItemProperty =
DependencyProperty.Register("SelectedItem", typeof(object), typeof(ExtendedSelector), new PropertyMetadata(default(object))); public static readonly DependencyProperty SelectionModeProperty =
DependencyProperty.Register("SelectionMode", typeof(SelectionMode), typeof(ExtendedSelector), new PropertyMetadata(SelectionMode.Single)); public static readonly DependencyProperty RepositionOnAddStyleProperty =
DependencyProperty.Register("RepositionOnAddStyle", typeof(PositionOnAdd), typeof(ExtendedSelector), new PropertyMetadata(PositionOnAdd.Default)); public PositionOnAdd RepositionOnAddStyle
{
get { return (PositionOnAdd)GetValue(RepositionOnAddStyleProperty); }
set { SetValue(RepositionOnAddStyleProperty, value); }
} public SelectionMode SelectionMode
{
get { return (SelectionMode)GetValue(SelectionModeProperty); }
set { SetValue(SelectionModeProperty, value); }
} public new object SelectedItem
{
get { return GetValue(SelectedItemProperty); }
set { SetValue(SelectedItemProperty, value); }
} public ExtendedSelector()
{
SelectionChanged += (sender, args) =>
{
if (SelectionMode == SelectionMode.Single)
SelectedItem = args.AddedItems[0];
else if (SelectionMode == SelectionMode.Multiple)
{
if (SelectedItem == null)
{
SelectedItem = new List<object>();
} foreach (var item in args.AddedItems)
{
((List<object>)SelectedItem).Add(item);
} foreach (var removedItem in args.RemovedItems)
{
if (((List<object>)SelectedItem).Contains(removedItem))
{
((List<object>)SelectedItem).Remove(removedItem);
}
}
}
}; Loaded += (sender, args) =>
{
((INotifyCollectionChanged)ItemsSource).CollectionChanged += (sender2, args2) =>
{
if (ItemsSource.Count > 0 && args2.NewItems != null)
{
switch (RepositionOnAddStyle)
{
case PositionOnAdd.NewItem:
int index = ItemsSource.IndexOf(args2.NewItems[0]); if (index >= 0)
ScrollTo(ItemsSource[index]);
break;
case PositionOnAdd.Top:
ScrollTo(ItemsSource[0]);
break;
}
}
};
};
}
}

 2.在xmal中使用 扩展ExtendedSelector 

a.定义数据模板

   <DataTemplate x:Name="LLSDataTemplate">
<ListBoxItem Margin="0,0,0,6">
<StackPanel>
<StackPanel Margin="0,0,0,12">
<TextBlock toolkit:SlideInEffect.LineIndex="1" Foreground="{StaticResource FontGroundThemeBrush}" TextWrapping="Wrap" FontSize="30" TextTrimming="None" Text="{Binding name}" />
<TextBlock toolkit:SlideInEffect.LineIndex="2" Foreground="{StaticResource FontGroundThemeBrush}" Opacity="0.7" TextWrapping="Wrap" TextTrimming="None" FontSize="18" Text="{Binding content}" />
</StackPanel>
</StackPanel>
</ListBoxItem>
</DataTemplate>

  b.定义LongListSelector的Style

 <Style x:Key="JumpListStyle" TargetType="phone:LongListSelector">
<Setter Property="GridCellSize" Value="111,111"/>
<Setter Property="LayoutMode" Value="Grid" />
<Setter Property="Margin" Value="18,12,0,0"/>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="{Binding Converter={StaticResource BackgroundConverter}}" Margin="6" >
<TextBlock Text="{Binding Key}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"
FontSize="48" Padding="11,0,0,1"
Foreground="{Binding Converter={StaticResource ForegroundConverter}}" VerticalAlignment="Bottom" />
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="GroupHeaderTemplate">
<Border Background="Transparent" Padding="5">
<Border Background="{StaticResource BackgroundThemeBrush}"
BorderBrush="{StaticResource BackgroundThemeBrush}"
Width="62" Height="62"
Margin="-6,0,18,6"
HorizontalAlignment="Left">
<TextBlock Text="{Binding Key}"
Foreground="{StaticResource PhoneForegroundBrush}"
FontSize="48"
Padding="6,6,6,11"
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
</Border>
</Border>
</DataTemplate>

  c.Page页面代码的实现

 <control:ExtendedSelector   Margin="12,0,12,24"   x:Name="ReaultListBox"
ItemsSource="{Binding SearchReaultItem, Mode=TwoWay}"
SelectedItem="{Binding SelectCydqItem,Mode=TwoWay}"
GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}"
HideEmptyGroups="True"
IsGroupingEnabled="True"
ItemTemplate="{StaticResource LLSDataTemplate}"
toolkit:TurnstileFeatherEffect.FeatheringIndex="1"
JumpListStyle="{StaticResource JumpListStyle}"
RepositionOnAddStyle="Top" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding SearchVM.SelectionChangedCommand,Source={StaticResource Locator}}" CommandParameter="{Binding Path=SelectedItem,ElementName=ReaultListBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers> </control:ExtendedSelector>

  

实现效果:

说明: RepositionOnAddStyle="Top" 有Top,Default,NewItem ,Top 为加载完数据后展示从头部开始 NewItem为加载完数据后展示从尾部开始

WindowsPhone8中LongListSelector的扩展解决其不能绑定SelectdeItem的问题的更多相关文章

  1. C# Webservice 解决在运行配置文件中指定的扩展时出现异常。 ---> System.Web.HttpException: 超过了最大请求长度问

    摘自: http://blog.csdn.net/gulijiang2008/article/details/4482993 请在服务器端配置 方法一: 在通过WebService处理大数据量数据时出 ...

  2. javascript中的数组扩展(一)

     javascript中的数组扩展(一) 随着学习的深入,发现需要学习的关于数组的内容也越来越多,后面将会慢慢归纳,有的是对前面的强化,有些则是关于前面的补充. 一.数组的本质    数组是按照次序排 ...

  3. MySQL中的空间扩展

    目录 19.1. 前言 19.2. OpenGIS几何模型 19.2.1. Geometry类的层次 19.2.2. 类Geometry 19.2.3. 类Point 19.2.4. 类Curve 1 ...

  4. [asp.net mvc 奇淫巧技] 03 - 枚举特性扩展解决枚举命名问题和支持HtmlHelper

    一.需求 我们在开发中经常会遇到一些枚举,而且这些枚举类型可能会在表单中的下拉中,或者单选按钮中会用到等. 这样用是没问题的,但是用过的人都知道一个问题,就是枚举的命名问题,当然有很多人枚举直接中文命 ...

  5. PHP中的MySQLi扩展学习(二)mysqli类的一些少见的属性方法

    虽说是少见的一些属性方法,但是可能还是有不少同学在日常的开发中使用过,这里只是学习了可能相对来说我们用得比较少的一些 mysqli 的属性或方法.就当是扩展一下自己的知识体系. 切换用户 首先就是切换 ...

  6. (转)ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法

    早上同事用PL/SQL连接虚拟机中的Oracle数据库,发现又报了"ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务"错误,帮其解决后,发现很多人遇到过这样的问 ...

  7. C#中Timer使用及解决重入问题

    C#中Timer使用及解决重入问题 ★介绍 首先简单介绍一下timer,这里所说的timer是指的System.Timers.timer,顾名思义,就是可以在指定的间隔是引发事件.官方介绍在这里,摘抄 ...

  8. EntityFramework 中支持 BulkInsert 扩展

    本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那 ...

  9. EntityFramework中支持BulkInsert扩展(转载)

    前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那可能得用上个几分钟.EntityFramework 最被人诟病的地方就是它的性能,处理大量数据时的效 ...

随机推荐

  1. SpringBoot 之 @ControllerAdvice 拦截异常并统一处理

    在spring 3.2中,新增了@ControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder.@ModelAttribute,并应用到所有@Requ ...

  2. 精尽 MyBatis 源码分析 - MyBatis 初始化(一)之加载 mybatis-config.xml

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...

  3. kali 系列学习04 - 漏洞扫描

    一.比较三类漏洞扫描工具 1.Rapid7 Nexpose 适合较大网络 2.Nessus 更经济,可以申请个人版,搞之后硬盘占用达到20G 以上2个是商业软件,使用容易上手,输入IP地址就能完成所有 ...

  4. xdebug不显示

  5. day95:flask:SQLAlchemy数据库查询进阶&关联查询

    目录 1.数据库查询-进阶 1.常用的SQLAlchemy查询过滤器 2.常用的SQLAlchemy查询结果的方法 3.filter 4.order_by 5.count 6.limit&of ...

  6. 用FL Studio来给电子音乐混音的方法

    FL Studio也算是音乐人用的比较多的编曲.混音软件了,FL Studio的一大的特色就是电子音乐的制作.尤其是对混音的操作,混音是电音制作过程中一个非常重要的环节,非常重要. 混音是什么?混音的 ...

  7. 合并2个数组为1个无重复元素的有序数组--Go对比Python

    Go实现: 1 package main 2 3 import ( 4 "fmt" 5 "sort" 6 ) 7 8 func main() { 9 var a ...

  8. 分析一个免杀webshell发现的php特性

    文章首发于t00ls,嫌文章太啰嗦的可以直接看结论 起源 之前看到别人分享的一个免杀webshell: <?php @$GLOBALS{next} = $GLOBALS[$GLOBALS[fun ...

  9. yii的pathinfo方式实现

    yii2.0在浏览器中默认查看控制器下的方法是  http://ltbk.cn/index.php?r=login/login 要是在浏览器上输出 http://ltbk.cn/index.php/l ...

  10. 基于混沌Logistic加密算法的图片加密与还原

    摘要 一种基于混沌Logistic加密算法的图片加密与还原的方法,并利用Lena图和Baboon图来验证这种加密算法的加密效果.为了能够体现该算法在图片信息加密的效果,本文还采用了普通行列置乱加密算法 ...