Thursday, May 29, 2014

Propagating Property Change for Static Properties

While working on any XAML based app, first thing which comes into mind is Binding. There are lot many articles on what is Binding and how it works. Don’t worry, I am not going to repeat all that stuff again. But definitely, I would like to touch upon few things which are base of my today’s write-up.

To make any property bindable or let’s say to propagate property change, we usually follow one of the below two options:
  • Implement INotifyPropertyChanged interface or
  • Create an event with name PropertyNameChanged

Point to notice here is, both the above options will work only on instance properties. Now what if my property is Static???

INotifyPropertyChanged is not going to work for static properties. None of the above options will make x:Static extension work.

What to do now ?

No worries, all these hazards can easily be overcome when you will jump to .Net 4.5.

Approach 1: Property specific static event for each and every static property
Let’s have a look at the below code:


Analysing Approach 1: Given approach will be feasible only when we have 1 or 2 static properties. If there are many static properties, then code will be bulky and un-maintainable as each property will have separate event.

Solution: Instead of writing static event for each and every static property, one generic event should be there.

Approach 2: Single Generic static event for all the static properties
Let’s have a look at the below code:

















Analysing Approach 2: This approach will work very smoothly irrespective of how many static properties are present in a given class.

Point worth mentioning about EventHandler parameters:

Why null is passed as a parameter in EventHandler?
First placeholder is for passing instance. But as this is Static property, instance value will be null. 

Hope you enjoyed learning this new feature.

Tuesday, May 27, 2014

Identify WPF version

If you want to figure out the current version of WPF installed on your machine, then one has to navigate to registry for below path:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup\Windows Presentation Foundation

Version value on above path will give your the required information.

Monday, May 12, 2014

.Net Framework 4.5.2 is available

Microsoft recently released .Net Fx 4.5.2 which is in-place update for .Net Framework 4, .Net Framework 4.5 and .Net Framework 4.5.1 and is ready for download on below links:

























This includes updates for ASP.Net, Windows Event Tracing (ETW), better profiling as well as for DPI settings. Enjoy...