PDFx – Property Dependency Framework – Part XVI, One Way Converters

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:

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.

10 thoughts on “PDFx – Property Dependency Framework – Part XVI, One Way Converters

  1. Pingback: PDFx – Property Dependency Framework – Part I, Introduction | //InterKnowlogy/ Blogs

  2. Pingback: PDFx – Property Dependency Framework – Part II, Library Versions | //InterKnowlogy/ Blogs

  3. Pingback: PDFx – Property Dependency Framework – Part V, Simple Property Dependencies | //InterKnowlogy/ Blogs

  4. Pingback: PDFx – Property Dependency Framework – Part VI, External Property Dependencies | //InterKnowlogy/ Blogs

  5. Pingback: PDFx – Property Dependency Framework – Part X, Caching | //InterKnowlogy/ Blogs

  6. Pingback: PDFx – Property Dependency Framework – Part XI, Smart Property Changed Notification | //InterKnowlogy/ Blogs

  7. Pingback: PDFx – Property Dependency Framework – Part XII, Callbacks | //InterKnowlogy/ Blogs

  8. Pingback: PDFx – Property Dependency Framework – Part XIII, Sanity Checks | //InterKnowlogy/ Blogs

  9. Pingback: PDFx – Property Dependency Framework – Part XIV, Data Delegation | //InterKnowlogy/ Blogs

  10. Pingback: PDFx – Property Dependency Framework – Part XV, Two Way Converters | //InterKnowlogy/ Blogs

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>