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

wpf example : RaiseAndSetIfChanged replace OnPropertyChanged #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yangjieshao
Copy link

@yangjieshao yangjieshao commented May 7, 2024

wpf example
RaiseAndSetIfChanged replace OnPropertyChanged

wpf example Reduce unnecessary OnPropertyChanges using ReferenceEquals
@yangjieshao yangjieshao changed the title wpf example : Reduce unnecessary OnPropertyChanges using ReferenceEquals wpf example : RaiseAndSetIfChanged replace OnPropertyChanged May 7, 2024
@secile
Copy link
Owner

secile commented May 14, 2024

Thank you for your contribution.

I confirmed that your code works correctly.
But there is a difference between current code and your code.

[Current code]
called OnPropertyChanged on every camera.PreviewCaptured.

[Your code]
called OnPropertyChanged first time only in camera.PreviewCaptured call.

This is because camera.Preview Capture passes a single-instance bitmap created by the library.
Therefore, the same instance is passed in every camera.PreviewCapture call.

It is true that the application is updating the screen without having to call OnPropertyChanged every time,
but I'm not sure which should be whether the current code or your code.

Could you tell me your opinion.

@yangjieshao
Copy link
Author

if (!ReferenceEquals(backingField, newValue))

只有当新的值和原来的值不是同一个对象的时候 才去调用 OnPropertyChanged
(Only call OnPropertyChanged when the new value is not the same object as the original value)

这样可以避免不必要的UI更新
(This can avoid unnecessary UI updates)

@secile
Copy link
Owner

secile commented May 28, 2024

Thank you for your response.

You said that your code can avoid unnecessary call of INotifyPropertyChanged.
But is it really unnecessary?

What worries me is that the reference of the Preview image hasn't changed, but the Preview image itself has changed.

This is a description of the INotifyPropertyChanged Interface

Notifies clients that a property value has changed.

According from the article, I think that I need to call INotifyPropertyChanged.

Off cource I know that your code works fine, but I want to choice the selection more safe.

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

Successfully merging this pull request may close these issues.

None yet

2 participants