Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnChangedInvokeMethodAttribute? #128

Open
yangf85 opened this issue Nov 15, 2023 · 2 comments
Open

OnChangedInvokeMethodAttribute? #128

yangf85 opened this issue Nov 15, 2023 · 2 comments

Comments

@yangf85
Copy link

yangf85 commented Nov 15, 2023

Does the Community Toolkit have a feature that allows calling a method when a property changes, similar to Fody?
like this.
feff5e4a1c030f2f139b6939c66aacff
thanks

@yangf85
Copy link
Author

yangf85 commented Nov 15, 2023

I know that partial methods can be used to implement a method call, but now there are multiple properties, and I don’t want to use the PropertyChanged += PropertyChanged event to handle them.
like this:
image

@echoix
Copy link

echoix commented Nov 15, 2023

If SearchValue is an ObservableProperty, you can do:

[ObservableProperty]
private string? searchValue;

partial void OnSearchValueChanged(string? value) 
{
    SearchGame();
}

There are at least 4 partial methods available that can be used for every observable property. Before the change and after the change. Two of them have the value before and after.

If SearchGame() is another property to simply get notified that it got changed (it doesn't have to be an observable property), like a "fullName" property that should be updated when either observable property "firstName" or "lastName" gets changed, you can use the NotifyPropertyChangedFor attribute, with the name of the property to get notified it should be updated too.

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

No branches or pull requests

2 participants