<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>//InterKnowlogy/ Blogs &#187; Kevin Stumpf</title>
	<atom:link href="http://blogs.interknowlogy.com/author/kevinstumpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.interknowlogy.com</link>
	<description>Blogging the Art of Software</description>
	<lastBuildDate>Fri, 17 May 2013 18:10:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part XVI, One Way Converters</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/#comments</comments>
		<pubDate>Fri, 17 May 2013 17:09:30 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4141</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>One Way Converters</h1>
<p><em>Although the following paragraph doesn&#8217;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.</em></p>
<p><em>The source code of the following example can be found in ViewModel ConverterDemonstrationVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>In <a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Two Way Converters</a> 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:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> ViewModel : BindableExt
{
	<span style="color: blue">private</span> Model Model { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

	<span style="color: blue">public</span> <span style="color: blue">string</span> MoneyQuantification
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; MoneyQuantification)
				.Depends(p =&gt; p.On(Model, k =&gt; k.MoneyInEuros));

			<span style="color: blue">if</span> (Model.MoneyInEuros &lt; 0)
			{
				<span style="color: blue">return</span> <span style="color: #a31515">"Not too much"</span>;
			}

			<span style="color: blue">if</span> (Model.MoneyInEuros &lt; 1000)
			{
				<span style="color: blue">return</span> <span style="color: #a31515">"A Little"</span>;
			}

			<span style="color: blue">if</span> (Model.MoneyInEuros &lt; 10000)
			{
				<span style="color: blue">return</span> <span style="color: #a31515">"Quite some"</span>;
			}

			<span style="color: blue">return</span> <span style="color: #a31515">"A Lot"</span>;
		}
	}
}

<span style="color: blue">class</span> Model : BindableExt
{
	<span style="color: blue">private</span> <span style="color: blue">double</span> _moneyInEuros = 100;
	<span style="color: blue">public</span> <span style="color: blue">double</span> MoneyInEuros
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _moneyInEuros; }
		<span style="color: blue">set</span>
		{
			_moneyInEuros = value;
			NotifyPropertyChanged(() =&gt; MoneyInEuros);
		}
	}
}
</pre>
</div>
<p>In this scenario, the PDFx ensures that the <em>MoneyQuantification</em> Property gets reevaluated whenever the Model&#8217;s <em>MoneyInEuros</em> Property changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part XV, Two Way Converters</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/#comments</comments>
		<pubDate>Fri, 17 May 2013 17:08:00 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4139</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Two Way Converters</h1>
<p><em>Although the following paragraph doesn&#8217;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.</em></p>
<p><em>The source code of the following example can be found in ViewModel ConverterDemonstrationVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>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.<br />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.</p>
<p>The PDFx allows you to enjoy the comfort of value converters (automatic reevaluation) within your ViewModels.</p>
<p>As explained in <a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Data Delegation</a>, the PDFx can be used to expose Model-data in the ViewModel.<br />The implementation of the <em>MoneyInUSD</em>-Property shows that the data doesn&#8217;t have to be delegated as is but can easily be transformed on the fly:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> ViewModel : BindableExt
{
	<span style="color: blue">private</span> Model Model { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

	<span style="color: blue">public</span> <span style="color: blue">double</span> MoneyInUSD
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; MoneyInUSD)
				.Depends(p =&gt; p.On(Model, k =&gt; k.MoneyInEuros));

			<span style="color: blue">return</span> Model.MoneyInEuros * 1.3;
		}
		<span style="color: blue">set</span> { Model.MoneyInEuros = value / 1.3; }
	}
}

<span style="color: blue">class</span> Model : BindableExt
{
	<span style="color: blue">private</span> <span style="color: blue">double</span> _moneyInEuros = 100;
	<span style="color: blue">public</span> <span style="color: blue">double</span> MoneyInEuros
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _moneyInEuros; }
		<span style="color: blue">set</span>
		{
			_moneyInEuros = value;
			NotifyPropertyChanged(() =&gt; MoneyInEuros);
		}
	}
}
</pre>
</div>
<p>In this scenario, the PDFx ensures that the <em>MoneyInUSD</em> Property gets reevaluated whenever the Model&#8217;s <em>MoneyInEuros</em> Property changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part XIV, Data Delegation</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/#comments</comments>
		<pubDate>Fri, 17 May 2013 17:05:40 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4137</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Simple Data Delegation</h1>
<p><em>Although the following paragraph doesn&#8217;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.</em></p>
<p><em>The source code of the following example can be found in ViewModel ConverterDemonstrationVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>More often than not, ViewModels wrap one or more instances of the Model Layer. Purists (like me) prefer to bind View-controls only to properties that come directly from the ViewModel layer rather than also to properties that come from the Model layer. This way they decouple their Model from the View and create a true MVVM architecture.<br />This approach, however, means that every Model-value the View eventually would like to display needs to be exposed by the ViewModel.</p>
<p>Let&#8217;s look at the following ViewModel implementation which wraps a Model and delegates its properties:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> ViewModel
{
	<span style="color: blue">private</span> Model Model { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

	<span style="color: blue">public</span> <span style="color: blue">double</span> MoneyInEuros
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> Model.MoneyInEuros; }
		<span style="color: blue">set</span> { Model.MoneyInEuros = value; }
	}
}

<span style="color: blue">class</span> Model : BindableExt
{
	<span style="color: blue">private</span> <span style="color: blue">double</span> _moneyInEuros = 100;
	<span style="color: blue">public</span> <span style="color: blue">double</span> MoneyInEuros
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _moneyInEuros; }
		<span style="color: blue">set</span>
		{
			_moneyInEuros = value;
			NotifyPropertyChanged(() =&gt; MoneyInEuros);
		}
	}
}
</pre>
</div>
<p>The problem with this purist approach is, however, that the data might change often directly in the Model layer without having passed through the ViewModel layer. <br />In the example above, the Model could represent an instance from a database. A service could now monitor the database and automatically reflect any changes that are applied to the database in the Model&#8217;s instance. Obviously, the ViewModel would not know about this change unless it explicitly monitors the <em>PropertyChanged</em> event of the Model instance.</p>
<p>This problem can easily be solved by employing the PDFx:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> ViewModel : BindableExt
{
	<span style="color: blue">private</span> Model Model { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

	<span style="color: blue">public</span> <span style="color: blue">double</span> MoneyInEuros
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; MoneyInEuros)
				.Depends(p =&gt; p.On(Model, k =&gt; k.MoneyInEuros));

			<span style="color: blue">return</span> Model.MoneyInEuros;
		}
		<span style="color: blue">set</span> { Model.MoneyInEuros = value; }
	}
}

<span style="color: blue">class</span> Model : BindableExt
{
	<span style="color: blue">private</span> <span style="color: blue">double</span> _moneyInEuros = 100;
	<span style="color: blue">public</span> <span style="color: blue">double</span> MoneyInEuros
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _moneyInEuros; }
		<span style="color: blue">set</span>
		{
			_moneyInEuros = value;
			NotifyPropertyChanged(() =&gt; MoneyInEuros);
		}
	}
}
</pre>
</div>
<p>In this scenario, the PDFx would automatically propagate the <em>MoneyInEuros</em> Property&#8217;s changes of the Model layer to the ViewModel layer.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part XIII, Sanity Checks</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/#comments</comments>
		<pubDate>Fri, 17 May 2013 17:04:01 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4135</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Sanity Checks</h1>
<p><em>Please refer to </em><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Library Versions</a><em></em><em> to find out whether your platform specific PDFx version supports Sanity Checks.</em></p>
<p>In Debug mode, the PDFx performs certain resource expensive Sanity Checks that try to capture typical developer mistakes that are not caught at compile time.</p>
<p>Both the <em>BindableExt&#8217;s</em> <em>Property</em> and <em>CachedValue</em> methods ensure that the Property that is being pointed to in the first method parameter equals the Property from which either method is being called.</p>
<p>In the following example, the PDFx notices upon first access of the properties <em>DependentPropertyMistake</em> and <em>CachedPropertyMistake</em> that the way they use the PDFx is incorrect.</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> WrongPDFXUsageDemonstration : BindableExt
{
	<span style="color: blue">private</span> <span style="color: blue">int</span> _inputValue;
	<span style="color: blue">public</span> <span style="color: blue">int</span> InputValue
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _inputValue; }
		<span style="color: blue">set</span>
		{
			_inputValue = value;
			NotifyPropertyChanged(() =&gt; InputValue);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> DependentPropertyMistake
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; InputValue) <span style="color: green">//Should point to DependentPropertyMistake</span>
				.Depends(p =&gt; p.On(() =&gt; InputValue));

			<span style="color: blue">return</span> InputValue*2;
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> DependentPropertyProper
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; DependentPropertyProper)
				.Depends(p =&gt; p.On(() =&gt; InputValue));

			<span style="color: blue">return</span> InputValue * 2;
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> CachedPropertyMistake
	{
		<span style="color: blue">get</span>
		{
			<span style="color: blue">return</span> CachedValue(() =&gt; InputValue, () =&gt; InputValue * 5);
			<span style="color: green">//Should point to CachedPropertyMistake</span>
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> CachedPropertyProper
	{
		<span style="color: blue">get</span>
		{
			<span style="color: blue">return</span> CachedValue(() =&gt; CachedPropertyProper, () =&gt; InputValue * 5);
		}
	}
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part XII, Callbacks</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/#comments</comments>
		<pubDate>Fri, 17 May 2013 17:01:16 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4133</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Callbacks</h1>
<p>When a source property changes, the PDFx allows you not only to automatically fire the <em>PropertyChanged</em> event for dependent properties, but also to execute callbacks in numerous scenarios.</p>
<p>The registration API for callbacks is not declarative, as the Property Dependency Registration API is, but rather imperative. Furthermore, the registration should not take place within a Property Getter but rather within a dedicated Registration method, as the following examples show.</p>
<h2>Callbacks on Property Changes</h2>
<p>The following example demonstrates how you can register Callbacks for normal Property Changes:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> SimpleCallbackExample : BindableExt
{
	<span style="color: blue">public</span> SimpleCallbackExample()
	{
		RegisterCallbacks();
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> RegisterCallbacks()
	{
		RegisterCallbackDependency(Property1, OnProperty1Changed);
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> OnProperty1Changed()
	{
		Debug.WriteLine(<span style="color: #a31515">"Property1 has changed!"</span>);
	}

	<span style="color: blue">private</span> AnyType _property1;
	<span style="color: blue">public</span> AnyType Property1
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _property1; }
		<span style="color: blue">set</span>
		{
			_property1 = value;
			NotifyPropertyChanged(() =&gt; Property1);
		}
	}
}
</pre>
</div>
<p>The used overload of <em>RegisterCallbackDependency</em> expects you to pass in the owner of a property as the first parameter, a delegate that points to the Property that is to be monitored as the second parameter and finally a pointer to the callback that is supposed to be executed when the Property changes.</p>
<p>In the example above, <em>OnProperty1Changed</em> will be executed by the PDFx whenever <em>Property1</em> changes.</p>
<h2>Callbacks on Objects</h2>
<p>The following example demonstrates how you can register one callback for all Property Changes of an object:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> ObjectCallbackExample : BindableExt
{
	<span style="color: blue">public</span> ObjectCallbackExample()
	{
		RegisterCallbacks();
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> RegisterCallbacks()
	{
		RegisterCallbackDependency(<span style="color: blue">this</span>, OnAnyPropertyChanged);
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> OnAnyPropertyChanged()
	{
		Debug.WriteLine(<span style="color: #a31515">"Any Property has changed!"</span>);
	}

	<span style="color: blue">private</span> AnyType _property1;
	<span style="color: blue">public</span> AnyType Property1
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _property1; }
		<span style="color: blue">set</span>
		{
			_property1 = value;
			NotifyPropertyChanged(() =&gt; Property1);
		}
	}

	<span style="color: blue">private</span> AnyType _property2;
	<span style="color: blue">public</span> AnyType Property2
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _property2; }
		<span style="color: blue">set</span>
		{
			_property2 = value;
			NotifyPropertyChanged(() =&gt; Property2);
		}
	}
}
</pre>
</div>
<p>The used overload of <em>RegisterCallbackDependency</em> expects you to pass in a property owner that is to be monitored as the first parameter and a pointer to the callback that is supposed to be executed when any Property changes as the second parameter.</p>
<p>In the example above, <em>OnAnyPropertyChanged</em> will be executed by the PDFx whenever <em>Property1</em> or <em>Property2</em> changes.</p>
<h2>Callbacks on Collections&#8217; children</h2>
<p>The PDFx also allows you to register callbacks that are to be fired when a specific property of an ObservableCollection&#8217;s child changes:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> CollectionPropertyCallbackExample : BindableExt
{
	<span style="color: blue">private</span> DependencyFrameworkObservableCollection&lt;Child&gt; _children 
		= <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;Child&gt;();

	<span style="color: blue">public</span> CollectionPropertyCallbackExample()
	{
		RegisterCallbacks();
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> RegisterCallbacks()
	{
		RegisterCallbackDependency(_children, k =&gt; k.Property1, OnCollectionChildPropertyChanged);
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> OnCollectionChildPropertyChanged()
	{
		Debug.WriteLine(<span style="color: #a31515">"Property1 of a child has changed!"</span>);
	}

	<span style="color: blue">private</span> <span style="color: blue">class</span> Child : BindableExt
	{
		<span style="color: blue">private</span> AnyType _property1;
		<span style="color: blue">public</span> AnyType Property1
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _property1; }
			<span style="color: blue">set</span>
			{
				_property1 = value;
				NotifyPropertyChanged(() =&gt; Property1);
			}
		}
	}
}
</pre>
</div>
<p>The first parameter of this <em>RegisterCallbackDependency</em> overload expects the collection that is to be monitored. The second parameter is to point to the Children&#8217;s Property that is of interest. The third parameter finally points to the callback that is to be executed.</p>
<p>In the example above, the method <em>OnCollectionChildPropertyChanged</em> will get fired whenever <em>Property1</em> of any child changes.</p>
<h2>Callbacks on entire Collections</h2>
<p>The PDFx also allows to register callbacks that get executed whenever any child&#8217;s property changes or a child gets added or removed:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> CollectionCallbackExample : BindableExt
{
	<span style="color: blue">private</span> DependencyFrameworkObservableCollection&lt;Child&gt; _children
		= <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;Child&gt;();

	<span style="color: blue">public</span> CollectionCallbackExample()
	{
		RegisterCallbacks();
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> RegisterCallbacks()
	{
		RegisterCallbackDependency(_children, OnCollectionChanged);
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> OnCollectionChanged()
	{
		Debug.WriteLine(<span style="color: #a31515">"Collection has changed!"</span>);
	}

	<span style="color: blue">private</span> <span style="color: blue">class</span> Child : BindableExt
	{
		<span style="color: blue">private</span> AnyType _property1;
		<span style="color: blue">public</span> AnyType Property1
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _property1; }
			<span style="color: blue">set</span>
			{
				_property1 = value;
				NotifyPropertyChanged(() =&gt; Property1);
			}
		}

		<span style="color: blue">private</span> AnyType _property2;
		<span style="color: blue">public</span> AnyType Property2
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _property2; }
			<span style="color: blue">set</span>
			{
				_property2 = value;
				NotifyPropertyChanged(() =&gt; Property2);
			}
		}
	}
}
</pre>
</div>
<p>The first parameter of the used <em>RegisterCallbackDependency</em> overload expects the ObservableCollection that is to be monitored. The second parameter points to the callback.</p>
<p>PDFx will automatically execute the callback whenever any property of a child changes and whenever the collection itself is modified either by adding or by removing a child.</p>
<h2>Deferred Callbacks</h2>
<p><em>Please refer to </em><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Library Versions</a><em></em><em> to find out whether the platform specific version of PDFx that you are using supports &#8220;Deferred Callbacks&#8221;</em></p>
<p>All the <em>RegisterCallbackDependency</em> overloads that are described in the paragraphs above are also available with the method <em>RegisterDeferredCallbackDependency</em> that allows you to register deferred callbacks.<br />If you register deferred callbacks, the execution of the callback is deferred by a certain amount of time (by default 100ms). Furthermore, if the callback trigger (such as a Property change) fires again before the wait time threshold has passed, the wait timer is reset. This feature gets especially useful when your callback is rather resource expensive and the underlying trigger might fire multiple times in a row.</p>
<p>Let&#8217;s look at the following example:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> SimpleCallbackExample : BindableExt
{
	<span style="color: blue">public</span> SimpleCallbackExample()
	{
		RegisterCallbacks();
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> RegisterCallbacks()
	{
		RegisterDeferredCallbackDependency(<span style="color: blue">this</span>, k =&gt; SliderValue, SubmitDataToServer);
	}

	<span style="color: blue">private</span> <span style="color: blue">void</span> SubmitDataToServer()
	{
		Debug.WriteLine(<span style="color: #a31515">"Expensive call to submit data to server..."</span>);
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _sliderValue;
	<span style="color: blue">public</span> <span style="color: blue">int</span> SliderValue
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _sliderValue; }
		<span style="color: blue">set</span>
		{
			_sliderValue = value;
			NotifyPropertyChanged(() =&gt; SliderValue);
		}
	}
}
</pre>
</div>
<p>In the example above, the <em>SliderValue</em> property could be bound to a slider. The requirement is to submit the slider&#8217;s new value to a server as soon as the user changes value. However, since a server call is rather expensive, the value should not be submitted while the user is still changing the value but rather as soon as the user finishes the change operation.<br />Such a requirement can easily be implemented by employing deferred callbacks as shown above.</p>
<h2>Extensive Example</h2>
<p>Please refer to WPFSample&#8217;s <em>CallbacksDemonstrationVM</em> to explore an example that makes heavy usage of the callback features.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part XI, Smart Property Changed Notification</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/#comments</comments>
		<pubDate>Fri, 17 May 2013 16:59:07 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4131</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Smart Property Changed Notification</h1>
<p>Whenever a property changes in a property dependency network, the PDFx can optionally first analyze all the property dependencies and then fire the <em>INotifyPropertyChanged.PropertyChanged</em> event only once for every directly or indirectly dependent property. This analysis saves tremendous amounts of precious CPU time since every <em>PropertyChanged</em> event causes your UI layer to access and thereby reevaluate the bound properties.</p>
<h2>Usage</h2>
<p>By default, the smart property changed notification is turned on.<br />If you have a reason to switch this behavior off, you can set the <em>Bindable</em> class&#8217;s <em>UseSmartPropertyChangedNotificationByDefault</em> Property to false.</p>
<h2>Performance Demonstration</h2>
<p><em>The source code of this example can be found in ViewModel SmartPropertyDependencyVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>Let us look at the following object graph:</p>
<p><img title="SmartPropertyChangeNotificationI.png" alt="SmartPropertyChangeNotificationI.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=679820"></p>
<p><em>Green circles stand for Input Properties while purple circles indicate calculated properties. The arrows show the underlying math operations as well as the property dependencies.</em></p>
<p>The number next to the lightning icon indicates how often the <em>INotifyPropertyChanged.PropertyChanged</em> event has fired since the <i>D1</i> Property has changed the last time.</p>
<p>A change of <em>D1</em> results in the following:</p>
<p><img title="SmartPropertyChangeNotificationII.png" alt="SmartPropertyChangeNotificationII.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=679822"></p>
<p>As the picture indicates, <em>INotifyPropertyChanged.PropertyChanged</em> is fired only once for every single property for maximum performance.</p>
<p>When the Smart Property Change Notification is switched off, a change of <em>D1</em> results in the following:</p>
<p><img title="SmartPropertyChangeNotificationIII.png" alt="SmartPropertyChangeNotificationIII.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=679823"></p>
<p>In this scenario, the PDFx does not analyze the Property Dependency Network before <em>INotifyPropertyChanged.PropertyChanged</em> events are fired but rather blindly performs a depth-search traversal down the dependency tree along all directly and indirectly dependent properties and fires <em>INotifyPropertyChanged.PropertyChanged</em> for every single property it finds. As shown above, this behavior results in 10 <em>PropertyChanged</em> Notifications for the root node, <i>A1</i>.</p>
<p>To be more specific, the PDFx traverses the tree in the following manner, if smart property change notification is switched off:</p>
<div style="color: black; background-color: white">
<pre>D1 -&gt; C1 -&gt; B1 -&gt; A1
	 -&gt; B2 -&gt; A1
   -&gt; C2 -&gt; B2 -&gt; A1
         -&gt; B3 -&gt; A1
   -&gt; C3 -&gt; B3 -&gt; A1
         -&gt; B4 -&gt; A1
   -&gt; C4 -&gt; B4 -&gt; A1
         -&gt; B5 -&gt; A1
   -&gt; C5 -&gt; B5 -&gt; A1
         -&gt; B6 -&gt; A1
</pre>
</div>
<p>It becomes obvious that the <em>PropertyChanged</em> event is inefficiently raised 10 times for Property <em>A1</em> although once would be completely sufficient. Consequently, it is advisable to always take advantage of the smart property notification.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part X, Caching</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/#comments</comments>
		<pubDate>Fri, 17 May 2013 16:52:16 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4129</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Caching</h1>
<p>The PDFx allows you to cache Property evaluations and thereby avoid unnecessary executions of the very same evaluation business logic while the underlying data stayed the same. <br />When the <em>INotifyPropertyChanged.PropertyChanged</em> event is fired for a property, its cached value gets invalidated because the PDFx assumes that the underlying data has changed.<br />If a cached property depends on other properties, the cached value consequently gets invalidated as soon as any of its direct or indirect source properties change.<br />This feature helps to save precious CPU time when property evaluations become costly.</p>
<p>The following example demonstrates the usage:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> CacheDemonstration : BindableExt
{
	<span style="color: blue">private</span> AnyType _property1;
	<span style="color: blue">public</span> AnyType Property1
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _property1; }
		<span style="color: blue">set</span> { _property1 = value; NotifyPropertyChanged(() =&gt; Property1); }
	}

	<span style="color: blue">private</span> AnyType _property2;
	<span style="color: blue">public</span> AnyType Property2
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _property2; }
		<span style="color: blue">set</span> { _property2 = value; NotifyPropertyChanged(() =&gt; Property2); }
	}

	<span style="color: blue">public</span> AnyOtherType DependentProperty
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; DependentProperty)
				.Depends(p =&gt; p.On(() =&gt; Property1)
				               .AndOn(() =&gt; Property2));

			<span style="color: blue">return</span> CachedValue(() =&gt; DependentProperty,
			                   () =&gt;
				               {
					               <span style="color: blue">return</span> Property1 + Property2;
				               });
		}
	}
}
</pre>
</div>
<p>To use the caching feature, simply wrap the Property&#8217;s evaluation logic in a call to the Method <em>CachedValue</em>. The first parameter points to the current property while the second parameter points to a delegate that evaluates the property&#8217;s business logic.</p>
<p>When <em>DependentProperty</em> is evaluated for the first time, it calculates the property&#8217;s value and caches it. Whenever the property is evaluated the next time, it returns the cached value without re-evaluating <em>Property1</em> or <em>Property2</em>.<br />As soon as <em>Property1</em> or <em>Property2</em> change, however, <em>DependentProperty&#8217;s</em> cached value is invalidated and upon its next access re-evaluated and cached again.</p>
<h2>Simple Example</h2>
<p>Let&#8217;s consider the following object graph:</p>
<p><img title="SimpleCachingExample.png" alt="SimpleCachingExample.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=679800"></p>
<p><em>Green circles stand for Input Properties while purple circles indicate calculated properties. The arrows show the underlying math operations as well as the property dependencies.</em></p>
<p>Such a graph can easily be implemented using the PDFx:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> SimpleCachingExample : BindableExt
{
	<span style="color: blue">public</span> <span style="color: blue">int</span> A1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; A1)
				.Depends(p =&gt; p.On(() =&gt; B1));

			<span style="color: blue">return</span> B1;
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> A2
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; A2)
				.Depends(p =&gt; p.On(() =&gt; B1));

			<span style="color: blue">return</span> 3 * B1;
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> B1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; B1)
				.Depends(p =&gt; p.On(() =&gt; C1)
							   .AndOn(() =&gt; C2));

			<span style="color: blue">return</span> CachedValue(() =&gt; B1, () =&gt;
				                             {
					                             <span style="color: blue">return</span> C1 + C2;
				                             });
			<span style="color: green">//Note the usage of CachedValue</span>
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _c1;
	<span style="color: blue">public</span> <span style="color: blue">int</span> C1
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _c1; }
		<span style="color: blue">set</span> { _c1 = value; NotifyPropertyChanged(() =&gt; C1); }
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _c2;
	<span style="color: blue">public</span> <span style="color: blue">int</span> C2
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _c2; }
		<span style="color: blue">set</span> { _c2 = value; NotifyPropertyChanged(() =&gt; C2); }
	}
}
</pre>
</div>
<p>A subsequent evaluation of <i>A1</i> and <i>A2</i> will result in only one evaluation of <i>B1</i>&#8216;s business logic. Any future request of <i>B1</i> will return the cached value. As soon as <i>C1</i> or <i>C2</i> change, <i>B1</i>&#8216;s cached value gets invalidated and reevaluated when its accessed the next time.</p>
<h2>Performance Demonstration</h2>
<p><em>The source code of this example can be found in ViewModel CachingDemonstrationVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>Let&#8217;s consider the following object graph:</p>
<p><img title="CachingExample.png" alt="CachingExample.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=679804"></p>
<p>The indicator next to the calculator icon shows the number of Property Evaluations since any Input Property (<i>E1</i> through <i>E6</i>) has last changed.</p>
<p>A change of E1 with caching enabled results in the following:</p>
<p><img title="CachingExampleII.png" alt="CachingExampleII.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=679805"></p>
<p>Only <i>D1</i>, <i>C1</i>, <i>B1</i> and <i>A1</i> get re-evaluated. This makes perfect sense, since those are the only properties that are directly or indirectly dependent on <i>E1</i>.</p>
<p>Without caching, however, a change of E2 results in the following:</p>
<p><img title="CachingExampleIII.png" alt="CachingExampleIII.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=679806"></p>
<p>The PDFx notices that <i>D1</i>, <i>C1</i>, <i>B1</i> and <i>A1</i> all need to get reevaluated and fires <em>INotifyPropertyChanged.PropertyChanged</em> for all of them. The UI layer consequently accesses all of them and causes a reevaluation. <br />A reevaluation of for example <i>A1</i> will now access &#8211; amongst others -<i>B1</i>. Consequently, B1 is unnecessarily evaluated again (first time it was evaluated by the UI layer). And the game goes on for all the other properties and has a larger performance impact the more intricate your object graph becomes.</p>
<p>The ViewModel for the example above can be implemented as follows:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> CachingDemonstrationVM : BindableExt
{
	<span style="color: blue">public</span> <span style="color: blue">int</span> A1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; A1)
				.Depends(p =&gt; p.On(() =&gt; B2)
							   .AndOn(() =&gt; B1));

			<span style="color: blue">return</span> CachedValue(() =&gt; A1, () =&gt; B1 + B2);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> B1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; B1)
				.Depends(p =&gt; p.On(() =&gt; C1)
							   .AndOn(() =&gt; C2));

			<span style="color: blue">return</span> CachedValue(() =&gt; B1, () =&gt; 2 * C1 - C2);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> B2
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; B2)
				.Depends(p =&gt; p.On(() =&gt; C2)
							   .AndOn(() =&gt; C3));

			<span style="color: blue">return</span> CachedValue(() =&gt; B2, () =&gt; -C2 + C3);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> C1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; C1)
				.Depends(p =&gt; p.On(() =&gt; D1)
							   .AndOn(() =&gt; D2));

			<span style="color: blue">return</span> CachedValue(() =&gt; C1, () =&gt; D1 + D2);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> C2
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; C2)
				.Depends(p =&gt; p.On(() =&gt; D3)
							   .AndOn(() =&gt; D4));

			<span style="color: blue">return</span> CachedValue(() =&gt; C2, () =&gt; 3 * D3 + 3 * D4);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> C3
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; C3)
				.Depends(p =&gt; p.On(() =&gt; D5)
							   .AndOn(() =&gt; D6));

			<span style="color: blue">return</span> CachedValue(() =&gt; C3, () =&gt; D5 + D6);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> D1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; D1)
				.Depends(p =&gt; p.On(() =&gt; E1));

			<span style="color: blue">return</span> CachedValue(() =&gt; D1, () =&gt; E1);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> D2
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; D2)
				.Depends(p =&gt; p.On(() =&gt; E2));

			<span style="color: blue">return</span> CachedValue(() =&gt; D2, () =&gt; E2);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> D3
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; D3)
				.Depends(p =&gt; p.On(() =&gt; E3));

			<span style="color: blue">return</span> CachedValue(() =&gt; D3, () =&gt; E3);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> D4
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; D4)
				.Depends(p =&gt; p.On(() =&gt; E4));

			<span style="color: blue">return</span> CachedValue(() =&gt; D4, () =&gt; E4);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> D5
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; D5)
				.Depends(p =&gt; p.On(() =&gt; E5));

			<span style="color: blue">return</span> CachedValue(() =&gt; D5, () =&gt; E5);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> D6
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; D6)
				.Depends(p =&gt; p.On(() =&gt; E6));

			<span style="color: blue">return</span> CachedValue(() =&gt; D6, () =&gt; E6);
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _e1;
	<span style="color: blue">public</span> <span style="color: blue">int</span> E1
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _e1; }
		<span style="color: blue">set</span>
		{
			_e1 = value;
			NotifyPropertyChanged(() =&gt; E1);
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _e2;
	<span style="color: blue">public</span> <span style="color: blue">int</span> E2
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _e2; }
		<span style="color: blue">set</span>
		{
			_e2 = value;
			NotifyPropertyChanged(() =&gt; E2);
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _e3;
	<span style="color: blue">public</span> <span style="color: blue">int</span> E3
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _e3; }
		<span style="color: blue">set</span>
		{
			_e3 = value;
			NotifyPropertyChanged(() =&gt; E3);
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _e4;
	<span style="color: blue">public</span> <span style="color: blue">int</span> E4
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _e4; }
		<span style="color: blue">set</span>
		{
			_e4 = value;
			NotifyPropertyChanged(() =&gt; E4);
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _e5;
	<span style="color: blue">public</span> <span style="color: blue">int</span> E5
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _e5; }
		<span style="color: blue">set</span>
		{
			_e5 = value;
			NotifyPropertyChanged(() =&gt; E5);
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _e6;
	<span style="color: blue">public</span> <span style="color: blue">int</span> E6
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _e6; }
		<span style="color: blue">set</span>
		{
			_e6 = value;
			NotifyPropertyChanged(() =&gt; E6);
		}
	}
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part IX, Dynamic Collection Dependencies</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/#comments</comments>
		<pubDate>Fri, 17 May 2013 16:48:32 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4124</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Dynamic Collection Dependencies</h1>
<h2>Declarative Usage</h2>
<p>As described in <a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Collection Dependencies</a>, the PDFx allows you to register dependencies not only on single objects&#8217;s properties, but also on ObservableCollections&#8217; children&#8217;s properties.</p>
<p>If the Collection is hotswappable, you can instruct the PDFx to listen for replacements of the entire collection instance:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> Demonstration : BindableExt
{
	DependencyFrameworkObservableCollection&lt;ChildClass&gt; _children = <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;ChildClass&gt;();
	<span style="color: blue">public</span> DependencyFrameworkObservableCollection&lt;ChildClass&gt; Children
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _children; }
		<span style="color: blue">set</span>
		{
			_children = value;
			NotifyPropertyChanged(() =&gt; Children);
		}
	}

	<span style="color: blue">public</span> AnyType CombinationOfAllChildren
	{
		<span style="color: blue">get</span>
		{
		       Property(() =&gt; CombinationOfAllChildren)
	                  .Depends(p =&gt; p.OnCollectionChildProperty(() =&gt; Children, k =&gt; k.ChildProperty));
		<span style="color: green">//Note how a delegate points to the Collections' property, </span>
                <span style="color: green">//thereby allowing the collection to be swapped out.</span>

		<span style="color: green">//Do something with all children and return</span>
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">void</span> ReplaceChildren()
	{
		Children = <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;ChildClass&gt;();
	}

	<span style="color: blue">class</span> ChildClass : INotifyPropertyChanged
	{
		<span style="color: blue">private</span> AnyType _childProperty;
		<span style="color: blue">public</span> AnyType ChildProperty
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _childProperty; }
			<span style="color: blue">set</span>
			{
				_childProperty = value;
				OnPropertyChanged(<span style="color: #a31515">"ChildProperty"</span>);
			}
		}
	}
}
</pre>
</div>
<p>Overloads of the methods <em>OnCollectionChildProperty</em> and <em>AndOnCollectionChildProperty</em> both allow you to pass in a <em>DependencyFrameworkObservableCollection</em> instance as the first parameter and point to any property of that collection&#8217;s children in the Lambda Expression you pass in as the second parameter. <br />To support hot swapping of the Collection&#8217;s instance, you pass a delegate to the <em>OnCollectionChildProperty</em> and <em>AndOnCollectionChildProperty</em> overloads, which points to the Property that contains the Collection.</p>
<h2>Example</h2>
<p><em>The source code of this example can be found in ViewModel DynamicCollectionDependencyVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>Let&#8217;s assume we are required to implement the following system:</p>
<p><img title="DynamicCollectionDependencyI.png" alt="DynamicCollectionDependencyI.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=678427"></p>
<p>By clicking the &#8220;Click here to use Children&#8221;-buttons, the user can change the source collection that ultimately feeds into the Destination object:</p>
<p><img title="DynamicCollectionDependencyII.png" alt="DynamicCollectionDependencyII.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=678428"></p>
<p><em>Green circles stand for Input Properties while purple circles indicate calculated properties. The arrows show the underlying math operations as well as the property dependencies.</em></p>
<p>Using the PDFx, we can easily implement the depicted system:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> DestinationVM : BindableExt
{
	<span style="color: blue">public</span> DestinationVM()
	{
		Children1 = <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt;();
		Children2 = <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt;();
		Children = Children1;

		Children1.Add(<span style="color: blue">new</span> ChildVM(Children1));
		Children1.Add(<span style="color: blue">new</span> ChildVM(Children1));
		Children1.Add(<span style="color: blue">new</span> ChildVM(Children1));

		Children2.Add(<span style="color: blue">new</span> ChildVM(Children2) { B1 = 2 });
		Children2.Add(<span style="color: blue">new</span> ChildVM(Children2) { B1 = 2 });
		Children2.Add(<span style="color: blue">new</span> ChildVM(Children2) { B1 = 2 });
	}

	<span style="color: blue">private</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; _children = <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt;();
	<span style="color: blue">public</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; Children
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _children; }
		<span style="color: blue">set</span>
		{
			_children = value;
			NotifyPropertyChanged(() =&gt; Children);
		}
	}
	
	<span style="color: blue">public</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; Children1 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
	<span style="color: blue">public</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; Children2 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

	<span style="color: blue">public</span> DelegateCommand AddToChildren1Command
	{
		<span style="color: blue">get</span>
		{
		<span style="color: blue">return</span> <span style="color: blue">new</span> DelegateCommand(() =&gt; Children1.Add(<span style="color: blue">new</span> ChildVM(Children1)));
		}
	}

	<span style="color: blue">public</span> DelegateCommand AddToChildren2Command
	{
		<span style="color: blue">get</span>
		{
		<span style="color: blue">return</span> <span style="color: blue">new</span> DelegateCommand(() =&gt; Children2.Add(<span style="color: blue">new</span> ChildVM(Children2)));
		}
	}

	<span style="color: blue">public</span> DelegateCommand UseLeftCommand
	{
		<span style="color: blue">get</span>
		{
			<span style="color: blue">return</span> <span style="color: blue">new</span> DelegateCommand(() =&gt; Children = Children1);
		}
	}

	<span style="color: blue">public</span> DelegateCommand UseRightCommand
	{
		<span style="color: blue">get</span>
		{
			<span style="color: blue">return</span> <span style="color: blue">new</span> DelegateCommand(() =&gt; Children = Children2);
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> A1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; A1)
				.Depends(p =&gt; p.On(() =&gt; B1).AndOn(() =&gt; B2));

			<span style="color: blue">return</span> B1 + B2;
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> B1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; B1)
		            .Depends(p =&gt; p.OnCollectionChildProperty(() =&gt; Children, k =&gt; k.A1));
			<span style="color: green">//Note how a delegate points to the Collections' property, </span>
			<span style="color: green">//thereby allowing the collection to be swapped out.</span>

			<span style="color: blue">if</span> (Children.Count == 0)
				<span style="color: blue">return</span> 0;

			<span style="color: blue">return</span> Children.Select(k =&gt; k.A1).Sum();
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _b2;
	<span style="color: blue">public</span> <span style="color: blue">int</span> B2
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _b2; }
		<span style="color: blue">set</span>
		{
			_b2 = value;
			NotifyPropertyChanged(() =&gt; B2);
		}
	}

	<span style="color: blue">class</span> ChildVM : BindableExt
	{
		<span style="color: blue">private</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; _children;

		<span style="color: blue">public</span> ChildVM(DependencyFrameworkObservableCollection&lt;ChildVM&gt; children)
		{
			_children = children;
		}

		<span style="color: blue">private</span> <span style="color: blue">int</span> _b1 = 1;
		<span style="color: blue">public</span> <span style="color: blue">int</span> B1
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _b1; }
			<span style="color: blue">set</span> { _b1 = value; NotifyPropertyChanged(() =&gt; B1); }
		}

		<span style="color: blue">public</span> <span style="color: blue">int</span> A1
		{
			<span style="color: blue">get</span>
			{
				Property(() =&gt; A1)
					.Depends(p =&gt; p.On(() =&gt; B1));

				<span style="color: blue">return</span> B1 * 3;
			}
		}

		<span style="color: blue">public</span> DelegateCommand RemoveCommand
		{
			<span style="color: blue">get</span>
			{
				<span style="color: blue">return</span> <span style="color: blue">new</span> DelegateCommand(() =&gt; _children.Remove(<span style="color: blue">this</span>));
			}
		}
	}
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part VIII, Collection Dependencies</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/#comments</comments>
		<pubDate>Fri, 17 May 2013 16:46:28 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4122</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Collection Dependencies</h1>
<h2>Declarative Usage</h2>
<p>The PDFx allows you to register dependencies not only on single objects&#8217;s properties, but also on ObservableCollections&#8217; children&#8217;s properties, given that they support the <em>INotifyPropertyChanged</em> interface:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> Demonstration : BindableExt
{
	DependencyFrameworkObservableCollection&lt;ChildClass&gt; _children = <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;ChildClass&gt;();
	
	<span style="color: blue">public</span> AnyType CombinationOfAllChildren
	{
		<span style="color: blue">get</span>
		{

		Property(() =&gt; CombinationOfAllChildren)
	           .Depends(p =&gt; p.OnCollectionChildProperty(_children, k =&gt; k.ChildProperty));
			
			<span style="color: green">//Do something with all children and return</span>
		}
	}

	<span style="color: blue">class</span> ChildClass : INotifyPropertyChanged
	{
		<span style="color: blue">private</span> AnyType _childProperty;
		<span style="color: blue">public</span> AnyType ChildProperty
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _childProperty; }
			<span style="color: blue">set</span>
			{
				_childProperty = value;
				OnPropertyChanged(<span style="color: #a31515">"ChildProperty"</span>);
			}
		}
	}
}
</pre>
</div>
<p>Overloads of the methods <em>OnCollectionChildProperty</em> and <em>AndOnCollectionChildProperty</em> both allow you to pass in a <em>DependencyFrameworkObservableCollection</em> instance as the first parameter and point to any property of that collection&#8217;s children in the Lambda Expression you pass in as the second parameter.</p>
<h2>DependencyFrameworkObservableCollection vs. ObservableCollection / INotifyCollectionChanged</h2>
<p>It is recommended to use the PDFx&#8217;s API with <em>DependencyFrameworkObservableCollections</em> when dependencies on collection&#8217;s children are to be registered, since the <em>DependencyFrameworkObservableCollection</em> offers significant property dependency performance advantages over the <em>ObservableCollection</em> or any other collection that implements <em>INotifyCollectionChanged</em>. It is, however, not required. <em>ObservableCollections</em> and other collections that implement <em>INotifyCollectionChanged</em> satisfy the API as well.</p>
<h2>Example</h2>
<p><em>The source code of this example can be found in ViewModel SimpleCollectionDependencyDemonstrationVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>Let&#8217;s assume we are required to implement the following system:</p>
<p><img title="SimpleCollectionDependency.png" alt="SimpleCollectionDependency.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=678416"><br /><em>Green circles stand for Input Properties while purple circles indicate calculated properties. The arrows show the underlying math operations as well as the property dependencies.</em></p>
<p>Using the PDFx, we can easily implement the depicted system:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> DestinationVM : BindableExt
{
	<span style="color: blue">public</span> DestinationVM()
	{
		Children.Add(<span style="color: blue">new</span> ChildVM(_children));
		Children.Add(<span style="color: blue">new</span> ChildVM(_children));
		Children.Add(<span style="color: blue">new</span> ChildVM(_children));
	}

	<span style="color: blue">private</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; _children = <span style="color: blue">new</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt;();
	<span style="color: blue">public</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; Children
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _children; }
	}

	<span style="color: blue">public</span> DelegateCommand AddCommand
	{
		<span style="color: blue">get</span>
		{
		  <span style="color: blue">return</span> <span style="color: blue">new</span> DelegateCommand(() =&gt; Children.Add(<span style="color: blue">new</span> ChildVM(Children)));
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> A1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; A1)
				.Depends(p =&gt; p.On(() =&gt; B1).AndOn(() =&gt; B2));

			<span style="color: blue">return</span> B1 + B2;
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">int</span> B1
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; B1)
			  .Depends(p =&gt; p.OnCollectionChildProperty(Children, k =&gt; k.A1));
			<span style="color: green">//Note the usage of the OnCollectionChildProperty method</span>

			<span style="color: blue">if</span> (Children.Count == 0)
				<span style="color: blue">return</span> 0;

			<span style="color: blue">return</span> Children.Select(k =&gt; k.A1).Sum();
		}
	}

	<span style="color: blue">private</span> <span style="color: blue">int</span> _b2 = 0;
	<span style="color: blue">public</span> <span style="color: blue">int</span> B2
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _b2; }
		<span style="color: blue">set</span>
		{
			_b2 = value;
			NotifyPropertyChanged(() =&gt; B2);
		}
	}

	<span style="color: blue">class</span> ChildVM : BindableExt
	{
		<span style="color: blue">private</span> DependencyFrameworkObservableCollection&lt;ChildVM&gt; _children;

		<span style="color: blue">public</span> ChildVM(DependencyFrameworkObservableCollection&lt;ChildVM&gt; children)
		{
			_children = children;
		}

		<span style="color: blue">private</span> <span style="color: blue">int</span> _b1 = 1;
		<span style="color: blue">public</span> <span style="color: blue">int</span> B1
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _b1; }
			<span style="color: blue">set</span> { _b1 = value; NotifyPropertyChanged(() =&gt; B1); }
		}

		<span style="color: blue">public</span> <span style="color: blue">int</span> A1
		{
			<span style="color: blue">get</span>
			{
				Property(() =&gt; A1)
					.Depends(p =&gt; p.On(() =&gt; B1));

				<span style="color: blue">return</span> B1 * 3;
			}
		}

		<span style="color: blue">public</span> DelegateCommand RemoveCommand
		{
			<span style="color: blue">get</span>
			{
				<span style="color: blue">return</span> <span style="color: blue">new</span> DelegateCommand(() =&gt; _children.Remove(<span style="color: blue">this</span>));
			}
		}
	}
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>PDFx &#8211; Property Dependency Framework &#8211; Part VII, Dynamic External Property Dependencies</title>
		<link>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/</link>
		<comments>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/#comments</comments>
		<pubDate>Fri, 17 May 2013 16:40:33 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=4113</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <em>INotifyPropertyChanged.PropertyChanged</em> 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.</p>
<p>I’ve developed the PDFx as an InterKnowlogy RECESS project and published the source code and examples on <a href="http://pdfx.codeplex.com">codeplex</a>.</p>
<p>In a series of blog posts I am going to cover the library’s most important features:</p>
<ul>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-i-introduction-2/">Part I: Introduction</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ii-library-versions/">Part II: Library Versions</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iii-getting-started/">Part III: Getting Started</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-iv-using-pdfx-with-an-existing-3rd-party-framework/">Part IV: Using PDFx with an existing 3rd party framework</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-v-simple-property-dependencies/">Part V: Simple Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">Part VI: External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/">Part VII: Dynamic External Property Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-viii-collection-dependencies/">Part VIII: Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-ix-dynamic-collection-dependencies/">Part IX: Dynamic Collection Dependencies</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-x-caching/">Part X: Caching</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xi-smart-property-changed-notification/">Part XI: Smart Property Changed Notification</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xii-callbacks/">Part XII: Callbacks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiii-sanity-checks/">Part XIII: Sanity Checks</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xiv-data-delegation/">Part XIV: Data Delegation</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xv-two-way-converters/">Part XV: Two Way Converters</a>
<li><a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-xvi-one-way-converters/">Part XVI: One Way Converters</a></li>
</ul>
<h1>Dynamic External Property Dependencies</h1>
<h2>Declarative Usage</h2>
<p>As shown in <a href="http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vi-external-property-dependencies/">External Property Dependencies</a>, the declarative PDFx API allows you to register a dependency on a property that resides in any <em>INotifyPropertyChanged</em>-instance different from the owner of the dependent Property.</p>
<p>If the owner of the source property can be swapped out at runtime (or start off as null), you can instruct PDFx to listen for changes of the owner object:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">class</span> SourceClass : INotifyPropertyChanged
{
	<span style="color: blue">private</span> AnyType _sourceProperty;
	<span style="color: blue">public</span> AnyType SourceProperty
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _sourceProperty; }
		<span style="color: blue">set</span>
		{
			_sourceProperty = value;
			OnPropertyChanged(<span style="color: #a31515">"SourceProperty"</span>);
		}
	}
}

<span style="color: blue">class</span> DestinationClass : BindableExt
{
	<span style="color: blue">private</span> SourceClass _dynamicSource;
	<span style="color: blue">private</span> SourceClass DynSource
	{
		<span style="color: blue">get</span> { <span style="color: blue">return</span> _dynamicSource; }
		<span style="color: blue">set</span>
		{
			_dynamicSource = value;
			NotifyPropertyChanged(() =&gt; DynSource);
		}
	}

	<span style="color: blue">public</span> AnyOtherType TargetProperty
	{
		<span style="color: blue">get</span>
		{
			Property(() =&gt; TargetProperty)
		            .Depends(p =&gt; p.On(() =&gt; DynSource, k =&gt; k.SourceProperty)); 
                        <span style="color: green">//Note that the first parameter of the On method is a delegate</span>

			<span style="color: green">//SourceProperty has changed. Do Something with it and return.</span>
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">void</span> ChangeSource()
	{
		DynSource = <span style="color: blue">new</span> SourceClass();
	}
}
</pre>
</div>
<p>Overloads of the methods <em>On</em> and <em>AndOn</em> both allow you to pass in an <em>INotifyPropertyChanged</em> instance as the first parameter and point to any property of that instance in the Lambda Expression you pass in as the second parameter.<br />To support hot swapping of the <em>INotifyPropertyChanged</em> instance, you pass in a delegate to the <em>On</em> and <em>AndOn</em> overloads, which points to the Property that contains the Source Property owner.</p>
<h2>Example</h2>
<p><em>The source code of this example can be found in ViewModel DynamicExternalDependencyVM which is part of the WPFSample&#8217;s source code.</em></p>
<p>Let&#8217;s assume we are required to implement the following graph:</p>
<p><img title="DynamicExternalPropertyDependenciesI.png" alt="DynamicExternalPropertyDependenciesI.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=678357"></p>
<p>By clicking the &#8220;Use External Source&#8221;-buttons, the user can change the source &#8220;External Source&#8221; that ultimately feeds into the Destination object:</p>
<p><img title="DynamicExternalPropertyDependenciesII.png" alt="DynamicExternalPropertyDependenciesII.png" src="http://download-codeplex.sec.s-msft.com/Download?ProjectName=PDFx&amp;DownloadId=678358"></p>
<p><em>Green circles stand for Input Properties while purple circles indicate calculated properties. The arrows show the underlying math operations as well as the property dependencies.</em></p>
<p>Using the PDFx, we can easily represent the depicted graph in C#:</p>
<div style="color: black; background-color: white">
<pre><span style="color: blue">public</span> <span style="color: blue">class</span> DynamicExternalDependencyVM : BindableExt
{
	<span style="color: blue">public</span> DynamicExternalDependencyVM()
	{
		ExternalSource1 = <span style="color: blue">new</span> ExternalSource();
		ExternalSource2 = <span style="color: blue">new</span> ExternalSource();
		Destination = <span style="color: blue">new</span> DestinationVM() { ExternalSource = ExternalSource1 };
	}

	<span style="color: blue">public</span> DestinationVM Destination { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
	<span style="color: blue">public</span> ExternalSource ExternalSource1 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
	<span style="color: blue">public</span> ExternalSource ExternalSource2 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

	<span style="color: blue">private</span> DelegateCommand _useExternalSource1Command;
	<span style="color: blue">public</span> DelegateCommand UseExternalSource1Command
	{
		<span style="color: blue">get</span>
		{
			<span style="color: blue">return </span>_useExternalSource1Command = _useExternalSource1Command ?? <span style="color: blue">new</span> DelegateCommand(() =&gt; Destination.ExternalSource = ExternalSource1);
			<span style="color: green">//Hotswap ExternalSource</span>
		}
	}

	<span style="color: blue">private</span> DelegateCommand _useExternalSource2Command;
	<span style="color: blue">public</span> DelegateCommand UseExternalSource2Command
	{
		<span style="color: blue">get</span>
		{
			<span style="color: blue">return </span>_useExternalSource2Command = _useExternalSource2Command ?? <span style="color: blue">new</span> DelegateCommand(() =&gt; Destination.ExternalSource = ExternalSource2);
			<span style="color: green">//Hotswap ExternalSource</span>
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">class</span> DestinationVM : BindableExt
	{
		<span style="color: blue">public</span> <span style="color: blue">int</span> A1
		{
			<span style="color: blue">get</span>
			{
				Property(() =&gt; A1)
					.Depends(p =&gt; p.On(() =&gt; B1)
						        .AndOn(() =&gt; ExternalSource, k =&gt; k.A1));
				<span style="color: green">//Tell the PDFx that ExternalSource might get hotswapped</span>

				<span style="color: blue">return</span> B1 + ExternalSource.A1;
			}
		}

		<span style="color: blue">private</span> ExternalSource _externalSource;
		<span style="color: blue">public</span> ExternalSource ExternalSource
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _externalSource; }
			<span style="color: blue">set</span>
			{
				_externalSource = value;
				NotifyPropertyChanged(() =&gt; ExternalSource);
			}
		}

		<span style="color: blue">private</span> <span style="color: blue">int</span> _b1;
		<span style="color: blue">public</span> <span style="color: blue">int</span> B1
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _b1; }
			<span style="color: blue">set</span>
			{
				_b1 = value;
				NotifyPropertyChanged(() =&gt; B1);
			}
		}
	}

	<span style="color: blue">public</span> <span style="color: blue">class</span> ExternalSource : BindableExt
	{
		<span style="color: blue">public</span> <span style="color: blue">int</span> A1
		{
			<span style="color: blue">get</span>
			{
				Property(() =&gt; A1)
					.Depends(p =&gt; p.On(() =&gt; B1));

				<span style="color: blue">return</span> 3 * B1;
			}
		}

		<span style="color: blue">private</span> <span style="color: blue">int</span> _b1;
		<span style="color: blue">public</span> <span style="color: blue">int</span> B1
		{
			<span style="color: blue">get</span> { <span style="color: blue">return</span> _b1; }
			<span style="color: blue">set</span>
			{
				_b1 = value;
				NotifyPropertyChanged(() =&gt; B1);
			}
		}
	}
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2013/05/17/pdfx-property-dependency-framework-part-vii-dynamic-external-property-dependencies/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
