Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

WPF: A proper way to execute method when property became true or false. #92

Open
Mallowan opened this issue Oct 16, 2020 · 1 comment
Open

Comments

@Mallowan
Copy link

Mallowan commented Oct 16, 2020

Could someone suggest a proper way to execute method when property changed to true or false?

       private bool _myProperty;
       public bool MyProperty
       {
           get { return _myProperty; }
           set { SetProperty(ref _myProperty, value); }
       }
     
@marbel82
Copy link

marbel82 commented Dec 1, 2020

Method Set() returns true when the value has changed.

        private bool _myProperty;
        public bool MyProperty
        {
            get => _myProperty;
            set
            {
                if (Set(ref _myProperty, value))
                    MyPropertyChanged();
            }
        }

PS, method SetProperty() is available in Prism.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants