Search code examples
silverlightsilverlight-3.0mvvm

MVVM - RaisePropertyChanged turning code into a mess


New to MVVM so please excuse my ignorance.

I THINK i'm using it right but I find my ViewModel has too many of these:

RaisePropertyChanged("SomeProperty")

Every time I set a property I have to raise that damned property changed.

I miss the days where I could just go:

public int SomeInteger { get; private set;}

These days I have to stick the "RaisePropertyChanged" in everywhere or my UI does not reflect the changes :(

Am I doing it wrong or are other people getting annoyed with the excessive number of magic strings and old school property setters?

Should I be using dependency properties instead? (I doubt that would help the code bloat anyway)

Despite these problems I still think MVVM is the way to go so I guess that's something.


Solution

  • Take a look at this What is the best or most interesting use of Extension Methods you've seen?.

    It describes an extension method and a helper method that my Model and ViewModel classes use to enable the following strongly typed (no magic string) properties.

    private string _name;
    public string Name
    {
        get { return _name; }
        set { this.NotifySetProperty(ref _name, value, () => this.Name); }
    }
    

    This is about as simple as I think it can get. Hope it helps.