0

im having a problem with my WPF application. I need to communicate through different ViewModels and i dont know exactly how. I dont want also to use a Framework, i have found the Mediator pattern and i have used it as a help class and it worked i called a method from an other Class but i dont know if is the perfect way to communicate with other ViewModels. Now my question really is how i can populate a combobox from a View1 with the selected item from it to my View2, ofc i have different ViewModels for each one and i want to saw the same on the two of them. For example : HERE!. I know that my ViewModels must only give orders on their Views and i think that i can also do that with the use of Mediator but i dont really know if this is a really good idea or there is a better way and exactly how i can do it. I have lost a week searching over what would be better to do, so i want a solution that would be the best and not against the MVVM pattern. Thanks in advance.

<ComboBox VerticalAlignment="Center" Grid.Column="1"  Grid.Row="0" IsEditable="False" IsSynchronizedWithCurrentItem="false" ItemsSource="{Binding combobox}" SelectedItem="{Binding selectedEmployee}" ItemTemplate="{StaticResource myResources}" />

MyViewModel

public ObservableCollection<ViewModelEmp> combobox
{ 
    get { return this._combobox; }
    set
    {
        this._combobox = value;
        OnPropertyChanged("combobox");
    }
}

I Use an ObserveableCollection in my class ViewModelEmp and i fill my combobox with a method from my database and then i'm calling them on my constructor:

public ViewModelEmp()
{
    this._combobox = new ObservableCollection<ViewModelEmp>();
    this.databaseconnect();
}

And like this i'm viewing on my combobox my Data from my Database, know if i want to show the same in an other View and ViewModel what exactly i can do?

Yoeri
  • 2,249
  • 18
  • 33

1 Answers1

0
Community
  • 1
  • 1
Yoeri
  • 2,249
  • 18
  • 33
  • Can you find for me an example Yoeri? – throwingexceptions Apr 19 '14 at 11:50
  • Anyone something guys? i need really help i cannot find a solution for my problem with my mediator. Can somebody explain me? Thanks in advance. – throwingexceptions Apr 20 '14 at 09:43
  • The links provided should suffice. INotifyPropertyChanged is just a somple interface. For an example of the messenger please refer to the example in the linked answer. I'll have a quick look around for an example of INotifyPropertyChanged and I'll post one if I find one. – Yoeri Apr 21 '14 at 11:09