This project is read-only.
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.

Two Way Converters

The source code of the following example can be found in ViewModel ConverterDemonstrationVM which is part of the WPFSample's source code.

Oftentimes developers use value converters to transform domain-specific data into other domain-specific data (e.g. convert a money value from one currency to another), and thereby scatter conversion business logic throughout the project by implementing it in various different converters (that technically belong to the UI layer). The reason for this typical behavior is simple: comfort. value converters get automatically reevaluated as soon as the input data changes and therefore they are an easy tool to display up-to-date transformed data in the UI.
From my point of view, however, value converters should be used mainly to convert domain-specific data to UI-specific data (e.g. convert a bool from the ViewModel to a Visibility for the View). All the massaged data, which eventually ends up in the View, should be exposed by the ViewModel. This way a new View could easily be plugged into the existing ViewModel and business logic is executed before it reaches the View layer.

The PDFx allows you to enjoy the comfort of value converters (automatic reevaluation) within your ViewModels.

As explained in Data Delegation, the PDFx can be used to expose Model-data in the ViewModel.
The implementation of the MoneyInUSD-Property shows that the data doesn't have to be delegated as is but can easily be transformed on the fly:

class ViewModel : BindableExt
	private Model Model { get; set; }

	public double MoneyInUSD
			Property(() => MoneyInUSD)
				.Depends(p => p.On(Model, k => k.MoneyInEuros));

			return Model.MoneyInEuros * 1.3;
		set { Model.MoneyInEuros = value / 1.3; }

class Model : BindableExt
	private double _moneyInEuros = 100;
	public double MoneyInEuros
		get { return _moneyInEuros; }
			_moneyInEuros = value;
			NotifyPropertyChanged(() => MoneyInEuros);

In this scenario, the PDFx ensures that the MoneyInUSD Property gets reevaluated whenever the Model's MoneyInEuros Property changes.

Last edited May 14, 2013 at 6:07 PM by KevinStumpf, version 4


No comments yet.