0

私はMVVMとListBoxのItemsSource Binding ListCollectionView Typeを使用しています。

SelectionMode="Multiple" で ListBox の Last SelectedItem を取得したい ListCollectionView の currentItem を取得する方法

現在、ListCollectionView の currentItem である最初の selectItem を取得できますが、ListCollectionView の currentItem である最後の SelectedItem を取得することはできません。

誰でも私を助けることができますか?または解決策を教えてください。

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

4

1 に答える 1

1

Prism の動作を使用できます。

public class LastSelectionBehavior:Behavior<ListBox>
{
    private ICollectionView _itemsSource;

    protected override void OnAttached()
    {
        base.OnAttached();

        _itemsSource = AssociatedObject.ItemsSource as ICollectionView;

        if (_itemsSource != null)
            AssociatedObject.SelectionChanged += AssociatedObjectSelectionChanged;
    }

    void AssociatedObjectSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count > 0)
            _itemsSource.MoveCurrentTo(e.AddedItems[0]);
    }
}

Xaml:

    <ListBox ItemsSource="{Binding Path=NamesView}" SelectionMode="Multiple">
        <i:Interaction.Behaviors>
            <local:LastSelectionBehavior/>
        </i:Interaction.Behaviors>
    </ListBox>
于 2013-08-05T13:07:58.793 に答える