Windows phone 8 WP8,LoopingSelector数据源中的空值
我正在使用Windows Phone Toolkit nuget软件包()。我想在我的WP8应用程序中创建一个LoopingSelector,在这里我可以选择日期,但我不希望LoopingSelector在它的选择中显示今天之前的几天 我的控件如下所示: 直到我选择了源代码的第一个元素(今天是2004年12月),我的应用程序才会有响应(我可以按按钮,显示效果,但事件处理程序不会执行)。我猜这是一个无限循环或死锁,但它不在我自己的代码中(我调试了它) LoopingSelector数据源的定义:Windows phone 8 WP8,LoopingSelector数据源中的空值,windows-phone-8,datepicker,datasource,toolkit,loopingselector,Windows Phone 8,Datepicker,Datasource,Toolkit,Loopingselector,我正在使用Windows Phone Toolkit nuget软件包()。我想在我的WP8应用程序中创建一个LoopingSelector,在这里我可以选择日期,但我不希望LoopingSelector在它的选择中显示今天之前的几天 我的控件如下所示: 直到我选择了源代码的第一个元素(今天是2004年12月),我的应用程序才会有响应(我可以按按钮,显示效果,但事件处理程序不会执行)。我猜这是一个无限循环或死锁,但它不在我自己的代码中(我调试了它) LoopingSelector数据源的定义:
public class NextDatesDataSource : LoopingDataSource<NextDateModel>
{
public NextDatesDataSource() : base(NextDateModel.Create(DateTime.Today)) { }
protected override NextDateModel GetNext(NextDateModel relativeTo)
{
if (relativeTo.Date == DateTime.Today + TimeSpan.FromDays(10))
return null;
return NextDateModel.Create(relativeTo.Date + TimeSpan.FromDays(1));
}
protected override NextDateModel GetPrevious(NextDateModel relativeTo)
{
//if i comment the next two lines, then everything works perfect
if (relativeTo.Date == DateTime.Today)
return null;
return NextDateModel.Create(relativeTo.Date - TimeSpan.FromDays(1));
}
}
多谢各位
public abstract class LoopingDataSource<T> : ILoopingSelectorDataSource
{
protected LoopingDataSource() { selectedItem = default(T); }
protected LoopingDataSource(T initialSelection) { selectedItem = initialSelection; }
protected abstract T GetNext(T relativeTo);
protected abstract T GetPrevious(T relativeTo);
public object GetNext(object relativeTo)
{
if (relativeTo == null) return null;
return GetNext((T)relativeTo);
}
public object GetPrevious(object relativeTo)
{
if (relativeTo == null) return null;
return GetPrevious((T)relativeTo);
}
private T selectedItem;
public object SelectedItem
{
get
{
return selectedItem;
}
set
{
object oldVal = selectedItem;
selectedItem = (T)value;
if (SelectionChanged != null)
SelectionChanged(this, new SelectionChangedEventArgs(new object[] { oldVal }, new object[] { value }));
}
}
public T Selected
{
get { return (T)SelectedItem; }
set { SelectedItem = value; }
}
public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
}
<p:LoopingSelector
x:Name="DaySelector"
Grid.Column="0" Grid.Row="1"
ItemSize="230,110"
ItemMargin="6" Margin="10,5,5,5">
<p:LoopingSelector.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Header}" FontSize="28" VerticalAlignment="Top"/>
<TextBlock Text="{Binding Body}" FontSize="42" FontWeight="Bold" VerticalAlignment="Bottom"/>
</Grid>
</DataTemplate>
</p:LoopingSelector.ItemTemplate>
</p:LoopingSelector>
DaySelector.DataSource = new NextDatesDataSource();