WindowsPhone8中LongListSelector的扩展解决其不能绑定SelectdeItem的问题
微软在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的问题的更多相关文章
- C# Webservice 解决在运行配置文件中指定的扩展时出现异常。 ---> System.Web.HttpException: 超过了最大请求长度问
摘自: http://blog.csdn.net/gulijiang2008/article/details/4482993 请在服务器端配置 方法一: 在通过WebService处理大数据量数据时出 ...
- javascript中的数组扩展(一)
javascript中的数组扩展(一) 随着学习的深入,发现需要学习的关于数组的内容也越来越多,后面将会慢慢归纳,有的是对前面的强化,有些则是关于前面的补充. 一.数组的本质 数组是按照次序排 ...
- MySQL中的空间扩展
目录 19.1. 前言 19.2. OpenGIS几何模型 19.2.1. Geometry类的层次 19.2.2. 类Geometry 19.2.3. 类Point 19.2.4. 类Curve 1 ...
- [asp.net mvc 奇淫巧技] 03 - 枚举特性扩展解决枚举命名问题和支持HtmlHelper
一.需求 我们在开发中经常会遇到一些枚举,而且这些枚举类型可能会在表单中的下拉中,或者单选按钮中会用到等. 这样用是没问题的,但是用过的人都知道一个问题,就是枚举的命名问题,当然有很多人枚举直接中文命 ...
- PHP中的MySQLi扩展学习(二)mysqli类的一些少见的属性方法
虽说是少见的一些属性方法,但是可能还是有不少同学在日常的开发中使用过,这里只是学习了可能相对来说我们用得比较少的一些 mysqli 的属性或方法.就当是扩展一下自己的知识体系. 切换用户 首先就是切换 ...
- (转)ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
早上同事用PL/SQL连接虚拟机中的Oracle数据库,发现又报了"ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务"错误,帮其解决后,发现很多人遇到过这样的问 ...
- C#中Timer使用及解决重入问题
C#中Timer使用及解决重入问题 ★介绍 首先简单介绍一下timer,这里所说的timer是指的System.Timers.timer,顾名思义,就是可以在指定的间隔是引发事件.官方介绍在这里,摘抄 ...
- EntityFramework 中支持 BulkInsert 扩展
本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那 ...
- EntityFramework中支持BulkInsert扩展(转载)
前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那可能得用上个几分钟.EntityFramework 最被人诟病的地方就是它的性能,处理大量数据时的效 ...
随机推荐
- Unity Lod
LOD是Level Of Detais 的简称,多细节层次,根据摄像机与物体距离,unity会自动切换模型.一般离摄像机近的时候显示高模,离摄像机远的时候显示低模,借此来提升性能. 如果你在Blend ...
- Flink处理函数实战之四:窗口处理
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- Folx中与下载相关的参数如何设置
Folx是一款简单易用,功能强大的MacOS专用下载管理工具.要使Folx下载/上传速度快,同时又不影响其他软件的上网使用,还能够有计划地安排下载,那么就必须对Folx进行参数设置.接下来小编详细讲解 ...
- FL Studio带你走进混音的世界
混音,是把多种音源整合到一个立体音轨或单音音轨中,通俗讲就是对多种声音进行调整后叠加在一起,这样可以让音乐听起来非常有层次感,尤其是在电音制作过程中,混音的质量更是起到了决定性的作用.音乐制作软件FL ...
- FL Studio音频混音教程
FL Studio是一款音乐制作.编曲.混音软件,其内置众多电子合成音色,还支持第三方VST等格式插件.软件操作界面简洁易上手,即使你是零音乐基础小白,通过它也能轻松实现自己音乐梦想,很多人给他起了个 ...
- 攻克弹唱第八课(吉他演奏的律动与funk音乐)
在本期文章中,笔者将为通过Guitar Pro 7吉他打谱软件与大家分享一下吉他律动与funk音乐的经验. 想必正在看这篇文章的进阶者和高手,都会考虑这样一个问题.我辛辛苦苦练习的大段solo和指弹曲 ...
- 使用Camtasia制作蒙面唱将揭面视频
要说之前的<蒙面唱将猜猜猜>还是属于比较火的歌唱综艺节目了.这档歌唱类型的综艺节目的精彩点不在于歌唱的水平,而在于猜想的环节.演唱时,嘉宾们都会蒙上面具,直到被评委猜中时才会揭开面具. 我 ...
- Mac支持的网络游戏有哪些?怎么支持Windows游戏?
"游戏是这个世界上唯一能和女性争夺男朋友的东西(/滑稽,有不少女生也喜欢玩游戏)."虽然只是一句玩笑话,不过也可以看出游戏对大多数男生来说是必不可少的一项娱乐活动了.而网络游戏是游 ...
- 如何基于App SDK快速地开发一个IoT App?
一.背景及大纲介绍 在如今物联网DCM(Device.Connect.Manage)的大框架下,有一个应用层来分析和处理数据,是必备技能.但是,对于一个公司来说,因为研发能力或者研发时间的原因,可能很 ...
- leetcode 493
//利用归并排序来完成,归并排序可参考前面代码,归并排序可用来完成这类逆序对之类的问题,采用分治的思想,对于归并排序的代码不需要多改动,只需要在归并之前进行一次寻找操作,找出count的数量 clas ...