WindowsPhone8中LongListSelector的扩展解决其不能绑定SelectdeItem的问题
2020-12-13 13:53
标签:style blog http io os ar 使用 for sp 微软在Wp8中集成了LongListSelector, 但是该控件在ViewModel中不能实现的SelectdeItem双向绑定,因为其不是DependencyProperty没办法只能实现扩展! 1.实现LongListSelector的扩展ExtendedSelector 2.在xmal中使用 扩展ExtendedSelector a.定义数据模板 b.定义LongListSelector的Style c.Page页面代码的实现 实现效果: WindowsPhone8中LongListSelector的扩展解决其不能绑定SelectdeItem的问题 标签:style blog http io os ar 使用 for sp 原文地址:http://www.cnblogs.com/fxiaoquan/p/4056822.html 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
说明: RepositionOnAddStyle="Top" 有Top,Default,NewItem ,Top 为加载完数据后展示从头部开始 NewItem为加载完数据后展示从尾部开始
上一篇:python3中map用法
文章标题:WindowsPhone8中LongListSelector的扩展解决其不能绑定SelectdeItem的问题
文章链接:http://soscw.com/essay/33446.html