0

I am new to C# programming, I am coming from a Java background and I have clear understanding on C# and the MVVM model. I am trying to develop a GUI client for FHIR server and am planning to use Firely Fhir library. What I know from the MVVM model is you have to implement INotifyPropertyChanged on the view model. Unfortunately the library I am trying to use, implements the INotifyPropertyChanged in the Model class.

I am confused shall I rewrite the Model class and remove the INotifyPropertyChanged implementation and implement it in the view model class instead?

Here is how the implementation of model class looks like now:

public partial class Patient
{
    [DataMember]
    public ResourceReference Organization
    {
        get { return _Organization; }
        set { _Organization = value; OnPropertyChanged("Organization"); }
    }

    private Hl7.Fhir.Model.ResourceReference _Organization;
}

I am planning to rewrite the model class and implement the INotifyPropertyChanged in the view model class.

Thanks

2
  • It is opinion-based. You will need to reflect the changes of M to VM. I don't think INPC shall not be used for such purpose. BTW, the title does not mach your question. Commented Jan 25 at 0:24
  • 1
    The "model" class can be plugged directly into the DataContext of the "View". Anything within the "scope" of that particular DataContext, can directly bind to its properties. If the "model" itself is "complete"; and implements INotify, etc. then no "view models" are needed; one simply provides one or more "interfaces" (to the model). A "property change notification" system is by subscriber; and the subscriber doesn't have to be the UI binding engine. There's no "shame" in building models that "publish (property) events" that any component can subscribe to; as this illustrates. Commented Jan 25 at 5:46

1 Answer 1

0

My thoughts are you have options:

  1. You can choose to have your VM subscribe to the model's INotifyPropertyChanged events

  2. You can refactor the model to fire a custom event when a model property changes, where the viewmodel implements INotifyPropertyChanged , subscribes to those events, updates the view/UI state using INotifyPropertyChanged

  3. If the app/scope is small, or it's a proof of concept, leave as is and let the viewmodel expose the model or wrap it lightly, as long as you don't mix business and UI logic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.