0

WPF ポップアップ ビューを ListCollectionView にバインドしました。次へ/前への 2 つのボタンがあるので、ユーザーがクリックすると、コレクションに移動できます。しかし、ユーザーが最後の要素にいるときに次へ(または最初の要素にいるときに前)をクリックすると問題が発生します。

「System.Reflection.TargetInvocationException」が発生します。MoveCurrentToNext/Previous が空のアイテムに移動しようとしているようです。ブレークポイントを使用してテストを行いました。コレクションに 2 つの要素があり、最後の要素にいるときに MoveCurrentToNext を使用できました。必要でないときにこのメソッドを使用しない解決策はありますか?

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);
    }
}

表示 (次へボタンの例)

<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>

助けてくれてありがとう。

4

0 に答える 0