0

I have got main ViewModel which contains Collection of data. It updates from Store by event. I want to send this collection to another ViewModel, which will show this data in view. But i have no idea how to notify another View Model. Data aren't shown in view. I am sure that every bindings in XAML are correct.

In debag i see than in every step Collection contains correct items,

Main view Model:

public class OpenedFileViewModel : ViewModelBase
{
    private DataGridStore _gridStore;
    public FileDataListingViewModel FileDataListingViewModel { get; set; }
    public ObservableCollection<ItemModel> ReadedItems => _gridStore?.ItemsCollection;
    public OpenedFileViewModel(DataGridStore _gridStore)
    {
       _gridStore.CurrentItemsChanged += OnCurrentFileDataChanged; // event when data in gridStore changed      
    }
    private void OnCurrentFileDataChanged()
    {
       OnPropertyChanged(nameof(ReadedItems));
       FileDataListingViewModel = new FileDataListingViewModel(ReadedItems);
    }
}

View Model which should show data:

public class FileDataListingViewModel : ViewModelBase
{
    private  ObservableCollection\<ItemModel\> \_itmes;
    public ObservableCollection\<ItemModel\> Items
    {
        get
        {
             return _itmes;
        }
        set
        {
        _itmes = value;
        OnPropertyChanged(nameof(Items));
       }
    }

    public FileDataListingViewModel(ObservableCollection<ItemModel> items)
    {
        Items = items;
        OnPropertyChanged(nameof(Items));
    }
}
iliyars
  • 1
  • 2
  • Why do you call OnPropertyChanged all over the place? You should always call it from the property setter. This helps you to understand your code for example to track down binding issues. For example FileDataListingViewModel is not raising the PropertyChanged event. Therefore the data binding that uses the FileDataListingViewModel as binding source won't update. And for the Items property the event is raised twice. Following a convention or best practice helps to reduce errors. ReadedItems should have a public get() and private set() so that it can raise the PropertyChanged event properly. – BionicCode Feb 26 '23 at 18:41
  • You should update your question and add sufficient code for a minimal reproduction. At the moment we need to read your code and guess at things. You can sometimes find when you use a base viewmodel implementing inotifypropertychanged out a class library the view somehow doesn't pick up that your viewmodel is implementing that interface. But we don't know what baseviewmodel is exactly, let alone where it is. We don't know how you compose these viewmodels and your views. – Andy Feb 27 '23 at 09:08

0 Answers0