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);
}
}
View (heavily stripped down):
<ListView ItemsSource="{Binding Pacientes}"/>
<Border DataContext="{Binding Pacientes/}">
<!-- some controls displaying properties of Paciente entity -->
</Border>
Note the Binding Pacientes/
with a trailing slash, trying to bind to Pacientes.CurrentItem
.
My intention here is to provide a Master/Detail view, with a ListView displaying all items, and a side panel displaying information from the Current/Selected Item.
The fact is: when I select an element in ListView, I would expect Pacientes.CurrentItem
to be set, but apparently it is not!
So my question is: how can I set ListCollectionView.CurrentItem by selecting an item on a data bound ListBox?
Set the IsSynchronizedWithCurrentItem
property:
<ListView ItemsSource="{Binding Pacientes}" IsSynchronizedWithCurrentItem="True"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With