Is it possible to detect property changes in a class from an external library?
Closed this issue · 2 comments
Regarding Patreon support
Once I'll get Donators / Sponsors for my open source ImageOptimizer I'll happily pass on some money to the OpenCollective.
https://github.com/devedse/DeveImageOptimizerWPF
Introduction
I'm currently building an image optimization application to help developers / users save bandwith and improve the world as a whole 😃.
What I'd like to do is to fully split the Logic from the UI stuff. This is why my logic is currently being released as a NuGet package which is then used within my WPF application.
The application I've built, optimizes images. The flow works as follows:
- MainViewModel has an
ObservableCollection<OptimizableFile>
- The class
OptimizableFile
is contained within the NuGet package
Flow:
- Whenever an image gets optimized an event will be triggered with a new
OptimizableFile
instance. - Once the Image is successfully optimized the
OptimizableFile
object has a status field which will be updated to 'Completed'. Once that's done, the same event will be fired again.
Ideally I would like to simply have the UI listen to changes to the OptimizableFile
class automatically and update the UI accordingly. Is this something that's possible?
Another usecase
The same would go for objects like Configuration. E.g. I'd have a default Configuration object inside my NuGet package which could be updated from the UI. So let's say you want to set the amount of images to process in parallel you would change this in the UI. This would then ideally be automatically propagated to the Configuration object inside the Optimizer class inside the NuGet package.
Alternative solution I currently used to work around this problem
Because I couldn't really get this to work I currently fixed this as follows:
- Made a copy of
ImageProgress
class:OptimizableFileUI
- Added the
[AddINotifyPropertyChangedInterface]
attribute - Once the event is fired from the ImageOptimizer I copy over all Property values from the Source to the one in the ObservableCollection.
(See: https://github.com/devedse/DeveImageOptimizerWPF/blob/master/DeveImageOptimizerWPF/State/ProcessingState/FileProgressState.cs#L71)
No this is not supported. Fody can only weave the target assembly produced by the current project. if you want notifications from instances in 3rd party libraries you will need to install Fody in the projects that produce those libs
@SimonCropp , thanks for the explanation! :)