How to synchronize ListCollectionView.CurrentItem and ListView.SelectedItem?

hel*_*ker 4 data-binding wpf listview listcollectionview collectionviewsource

I have a ViewModel containing a ListCollectionView property, and a View containing a ListView control whose ItemsSource property is data bound to the ListCollectionView:

ViewModel:

    public ListCollectionView Pacientes { get; set; }

    public IRepositório<Paciente> RepositórioPacientes { get; set; }


    // CONSTRUTOR
    public MainViewModel()
    {
        RepositórioPacientes = new PacienteRepositorioFake();

        Pacientes = (ListCollectionView)CollectionViewSource.GetDefaultView(RepositórioPacientes.Items);
    }
}
Run Code Online (Sandbox Code Playgroud)

View (heavily stripped down):

    <ListView ItemsSource="{Binding Pacientes}"/>
    <Border DataContext="{Binding Pacientes/}">
        <!-- some controls displaying properties of Paciente entity -->
    </Border>
Run Code Online (Sandbox Code Playgroud)

Note the Binding Pacientes/ with a trailing slash, trying to bind to Pacientes.CurrentItem.

我的目的是提供一个主视图/详细视图,其中的ListView显示所有项目,而侧面板则显示当前/选定项目的信息。

事实是:当我在ListView中选择一个元素时,希望Pacientes.CurrentItem可以设置它,但显然不是这样!

所以我的问题是:如何通过在数据绑定的ListBox上选择一个项目来设置ListCollectionView.CurrentItem?

Cle*_*ens 5

设置IsSynchronizedWithCurrentItem属性:

<ListView ItemsSource="{Binding Pacientes}" IsSynchronizedWithCurrentItem="True"/>
Run Code Online (Sandbox Code Playgroud)