C# ListCollectionView异常错误“;系统.反射.目标职业例外“;导航时
我已将WPF弹出视图与ListCollectionView绑定。我有两个按钮“下一个/上一个”,因此当用户单击时,他可以导航到集合。但是当用户在最后一个元素上单击next(或在第一个元素上单击previous)时,我遇到了问题 我得到一个“系统。反射。目标异常”。似乎MoveCurrentToNext/Previous试图处理一个空项目。我用断点做了一个测试,集合中有两个元素,当我在最后一个元素上时,我可以使用MoveCurrentToNext。在没有必要的情况下,有没有办法不使用这种方法C# ListCollectionView异常错误“;系统.反射.目标职业例外“;导航时,c#,wpf,listcollectionview,targetinvocationexception,C#,Wpf,Listcollectionview,Targetinvocationexception,我已将WPF弹出视图与ListCollectionView绑定。我有两个按钮“下一个/上一个”,因此当用户单击时,他可以导航到集合。但是当用户在最后一个元素上单击next(或在第一个元素上单击previous)时,我遇到了问题 我得到一个“系统。反射。目标异常”。似乎MoveCurrentToNext/Previous试图处理一个空项目。我用断点做了一个测试,集合中有两个元素,当我在最后一个元素上时,我可以使用MoveCurrentToNext。在没有必要的情况下,有没有办法不使用这种方法 pu
public class PopupViewModel : Screen
{
private readonly PopupManager manager = new PopupManager();
public ListCollectionView AlertCollectionView { get; set; }
public void PreviousRecordExecute()
{
this.AlertCollectionView.MoveCurrentToPrevious();
}
public void NextRecordExecute()
{
this.AlertCollectionView.MoveCurrentToNext();
}
private FeedItem CurrentAlert
{
get
{
return AlertCollectionView.CurrentItem as FeedItem;
}
set
{
AlertCollectionView.MoveCurrentTo(value);
NotifyOfPropertyChange();
}
}
[ImportingConstructor]
public PopupViewModel()
{
manager.GetPopData().CollectionChanged += (s, e) => AlertCollectionView.Refresh();
AlertCollectionView = new ListCollectionView(manager.GetPopData());
AlertCollectionView.MoveCurrentToPosition(0);
}
}
视图(下一步按钮示例)
感谢您的帮助。请提供可靠的重现问题的方法。除此之外,通过查看正在抛出的
targetingException
的InnerException
属性值,自己调试它。我问这个问题是因为我在控制台中看到,当我单击next按钮时,我会转到next元素,即使它是最后一个元素。所以,我在问我是否必须创建一个函数来不执行MoveCurrentTo。。。若并没有剩下任何元素,或者ListCollectionView有方法来执行此操作。
<ItemsControl Margin="369,87,10,304">
<Button Height="19" Width="19" BorderThickness="0" Margin="1,0" BorderBrush="{x:Null}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="NextRecordExecute"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFFC500"/>
<GradientStop Color="#FFF1E29E" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
</ItemsControl>