Search code examples
c#wpfmvvmmaster-detail

MVVM Pattern in Master-Detail when editing details


i have a ObservableCollection with some data. They are displayed as Master (ListBox) and Detail (some Labels). I use binding and IsSynchronizedWithCurrentItem to show the correct details to the selected master item. This works all fine. Now i want to edit some details (load different image). I implemeted this a a Button Command in the ViewModel.

But how do i know which item is selected (UI) in the ViewModel-layer ?

Thanks for help


Solution

  • I don't really find the IsSynchronizedWithCurrentItem property that useful in MVVM scenarios. Just expose another SelectedItem property in the ViewModel.

    public ItemType SelectedItem
    {
        get { return _selectedItem; }
        set
        {
            _selectedItem = value;
            // your logic here
        }
    }