views:

214

answers:

3

I have a database that communicates with webservices with my Model (own thread) and exposes Data Objects. My UI application consists of different Views and ViewModels and Custom Controls. I'm using ServiceProvider (IServiceProvider) to access the Model and route the events to the UI thread. Communication between the ViewModels is handeled by a Messenger.

Is this way to go?

I was also wondering what is the best way to strucutre the DataObjects

At the moment i have the DataObjects that have a hierarchy structure but does not support INotifyProperty though the children list are of type of ObservableCollection. I have no possiblity to implement notifypropertychange on the properties.

I was wondering the best way of making them MVVM friendly. Implementing a partial class and adding all the properties or commands that are necessary or wrapping all the DataObjects and keep the Model list and MVVM list in sync.

All thoughts and ideas are appreciated.

A: 

ASPNET MVC works pretty well

Orestes C.A.
Actually this is a WPF application that is commuicating with a webservice.
Dzenand
ASP.NET MVC has nothing to do with MVVM...
Thomas Levesque
patterns aren't frameworks
Gabriel Ščerbák
+1  A: 

Strictly implementing MVVM means that you should create ViewModel classes that expose all the DataObjects (your Model) that will be used the View - the View should not be able to access the Model directly.

Following this, you will have full control over your ViewModel and you'll be able to implement INotifyPropertyChange events and synchronise the ViewModel with the Model on each change notification or upon specific actions.

Bermo
+1  A: 

I would agree with Bermo with a note that not many people do not strictly implement the pattern. May expose the Model objects directly and implement INotifyPropertyChanged in those objects. But below is the basic means you can use to implement what you have so far:

class PersonViewModel : INotifyPropertyChanged
{
    Person p = new Person();

    public string First
    {
        get { return p.First; }
        set
        {
            p.First = value;
            onPropertyChanged("First");
        }
    }

    public string Last
    {
        get { return p.Last; }
        set
        {
            p.Last = value;
            onPropertyChanged("Last");
        }
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    private void onPropertyChanged(string propertyName)
    {
        if (PropertyChanged!=null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName);
        }
    }

    #endregion
}

I personally created a ViewModel class to inherit from so that I could put my INotifyPropertyChanged code there and not have to put it in repeatedly. Then my implementations simply inherit from that base class.

Kirk