The PDFx is a lightweight open source .NET library that allows developers to describe dependencies between Properties in declarative C# code. Once relationships are registered, the framework monitors property changes and ensures that the INotifyPropertyChanged.PropertyChanged event is fired for all directly and indirectly dependent properties in a very efficient way. The library is available for WPF, Silverlight, WinRT (Windows Store) and Windows Phone.
I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on codeplex.
In a series of blog posts I am going to cover the library’s most important features:
- Part I: Introduction
- Part II: Library Versions
- Part III: Getting Started
- Part IV: Using PDFx with an existing 3rd party framework
- Part V: Simple Property Dependencies
- Part VI: External Property Dependencies
- Part VII: Dynamic External Property Dependencies
- Part VIII: Collection Dependencies
- Part IX: Dynamic Collection Dependencies
- Part X: Caching
- Part XI: Smart Property Changed Notification
- Part XII: Callbacks
- Part XIII: Sanity Checks
- Part XIV: Data Delegation
- Part XV: Two Way Converters
- Part XVI: One Way Converters
One Way Converters
Although the following paragraph doesn’t describe a new feature of the PDFx, it demonstrates a use case that solves a common problem developers face every day, apart from the sole monitoring of large Property Dependency networks.
The source code of the following example can be found in ViewModel ConverterDemonstrationVM which is part of the WPFSample’s source code.
In Two Way Converters I argue that value converters should be used exclusively to convert business domain data to UI specific data rather than to solely transform business domain data. I also showed how the PDFx can be employed to render two-way value converters, which convert domain data, redundant. The very same pattern can be applied to mimic the behavior of one way value converters in your ViewModel:
class ViewModel : BindableExt { private Model Model { get; set; } public string MoneyQuantification { get { Property(() => MoneyQuantification) .Depends(p => p.On(Model, k => k.MoneyInEuros)); if (Model.MoneyInEuros < 0) { return "Not too much"; } if (Model.MoneyInEuros < 1000) { return "A Little"; } if (Model.MoneyInEuros < 10000) { return "Quite some"; } return "A Lot"; } } } class Model : BindableExt { private double _moneyInEuros = 100; public double MoneyInEuros { get { return _moneyInEuros; } set { _moneyInEuros = value; NotifyPropertyChanged(() => MoneyInEuros); } } }
In this scenario, the PDFx ensures that the MoneyQuantification Property gets reevaluated whenever the Model’s MoneyInEuros Property changes.
Pingback: PDFx – Property Dependency Framework – Part I, Introduction | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part II, Library Versions | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part V, Simple Property Dependencies | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part VI, External Property Dependencies | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part X, Caching | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part XI, Smart Property Changed Notification | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part XII, Callbacks | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part XIII, Sanity Checks | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part XIV, Data Delegation | //InterKnowlogy/ Blogs
Pingback: PDFx – Property Dependency Framework – Part XV, Two Way Converters | //InterKnowlogy/ Blogs