Fody / PropertyChanged

Injects INotifyPropertyChanged code into properties at compile time
MIT License
1.89k stars 228 forks source link

Model to ViewModel #315

Closed leroygumede closed 6 years ago

leroygumede commented 6 years ago

I know its a stupid Question But how do I Intercept From Model to ViewModel ?

I tried putting this in my ViewModel but nothing happens, Am I missing something ? I'm Using Xamarin Forms, Prism Model

   public class Question : INotifyPropertyChanged
    {
        public bool IsValid { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string propertyName)
        {
            Debug.WriteLine("This Works Here :) ");
            var propertyChanged = PropertyChanged;
            if (propertyChanged != null)
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

ViewModel

public class MainPageViewModel : INavigationAware, INotifyPropertyChanged{
        public virtual void OnPropertyChanged(string propertyName)
        {
            Debug.WriteLine("It Does not reach here :( ");
        }

        public static void Intercept(object target, Action onPropertyChangedAction, string propertyName)
        {
            Debug.WriteLine("It Does not reach here too :( ");
            onPropertyChangedAction();
        }
}

Do I need to use PropertyChangedNotificationInterceptor ? How do I implement it in my View-Model , Any advice would be awesome

SimonCropp commented 6 years ago

i am a little confused as to your scenario. this project just implements INPC. it does not map between view model and model.

Perhaps share a working solution of what you want to achieve?

leroygumede commented 6 years ago

@SimonCropp Thanks for the reply :), I created a sample Here. . In Short I have a Group List and I want a Event handler when a user selects a item.

It works and gets fires in the Model

       public bool IsVisible { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string propertyName)
        {
            Debug.WriteLine("It works here");
            var propertyChanged = PropertyChanged;
            if (propertyChanged != null)
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

But For some reason It does not get to the ViewModel(MainPageViewModel.cs) (When you disable a checkbox , I want to review the list Items and later on show and hide items)

SimonCropp commented 6 years ago

so how would you make it work if u were not using propertychanged.fody?

leroygumede commented 6 years ago

The main problem had to do with my Grouping logic and was not a fody issue , all is resolved :) . I was trying to fix a problem with fody rather than fix the problem itself.