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 最被人诟病的地方就是它的性能,处理大量数据时的效 ...
随机推荐
- HTTP请求响应信息字段总结(长期更新)
http头的Location和Conten-Location HTTP响应细节--常用响应头 HTTP响应中的常用响应头(消息头) Location: 服务器通过这个头,来告诉浏览器跳到哪里 Serv ...
- bWAPP----HTML Injection - Stored (Blog)
HTML Injection - Stored (Blog) 界面 1 <div id="main"> 2 3 <h1>HTML Injection - S ...
- guitar pro系列教程(十五):Guitar Pro播放没有声音怎么办?
相信很多朋友在安装了guitar pro打谱后都会发现没有声音,关于这个问题相信大家都很苦恼到底是什么问题呢,今天小编就这个问题与大家好好讨论讨论,希望对大家有帮助,感兴趣的朋友可以进来一起学习哦. ...
- JavaScript中的链式调用
链模式 链模式是一种链式调用的方式,准确来说不属于通常定义的设计模式范畴,但链式调用是一种非常有用的代码构建技巧. 描述 链式调用在JavaScript语言中很常见,如jQuery.Promise等, ...
- 浅谈 van Emde Boas 树——从 u 到 log log u 的蜕变
本文参考算法导论完成. 模板题在此 QwQ 优化的过程比较长,还请读者耐心阅读,认真理解. 最初的想法 我会暴力! 用一个 \(size\) 数组维护每个元素出现的次数. 不细讲,时间复杂度 \(O( ...
- Java基础教程——使用Eclipse快速编写Java输入输出代码
Eclipse安装 IDE:Integrated Development Environment,集成开发环境.好比是全自动洗衣机. 此处使用[eclipse-jee-4.6-neon-3-win32 ...
- Android多触点总结
文章部分内容参考: http://blog.csdn.net/barryhappy/article/details/7392326 总结: 1. event.getX()可以得到x的坐标,里面的参数0 ...
- PyQt(Python+Qt)学习随笔:QMdiArea多文档界面区域的viewMode、documentMode、tabsClosable、tabPosition等属性介绍
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 viewMode属性用于控制子窗口是使用子窗口模式(QMdiArea. ...
- PyQt(Python+Qt)学习随笔:Qt Designer中toolBar的movable属性
1.概述 movable属性用来确认toolBar是否可以移动,如果设置为可移动,则toolBar可以在主窗口范围内拖拽移动. 2.访问方法 通过isMovable().setMovable(bool ...
- Monkey 部署环境
Monkey的介绍 它是Android系统自带一个命令行工具,可以运行在模拟器里或者真是设备中运行. Monkey是发送伪随机用户事件的工具. Monkey向系统发送伪随机的用户事件流,实现对正在开发 ...