A in XAML: Ain’t for WPF/Silverlight

Even though XAML is officially the acronym of eXtensible Application Markup Language,- a generic term-, you can not usually separate it from UI frameworks, WPF and Silverlight. This creates some confusion, most people think of WPF as the declaration of UI with XML. Not that this is wrong, this explanation does not necessarily suggest decoupling data, logic and user interaction. XAML only helps WPF to achieve it, there is definitely more in WPF. I admit, XAML originally stood for eXtensible Avalon (code-name for WPF) Markup Language. But hey, there is more in XAML, too.

Since the first day I learned about WPF, I almost never used a UI designer tool. Perhaps, that is why I started using XAML everywhere I could, one could say it was love at first sight. They say love lasts roughly 3 years and even though it has been a little bit longer than that for me, I still feel strong about it. Lucky for me, Microsoft does also. Together with the recent release of VS2010 Beta 2, XAML finally has its own assembly, System.Xaml.dll targeting .NET Framework 4 Beta 2. I have now plenty of projects which can loose their dependencies on PresentationCore.dll, PresentationFramework.dll and WindowsBase.dll. I hope to convert them all easily and start making more.

First one to go was my almost forgotten open-source project Geostructor. I was expecting minor problems but I was wrong. I had none except the fact that, I had unconsciously created dependencies on WPF assemblies. After moving those dependent codes to where they really belong, I was ready to go with one little replacement. Replaced all class references of XamlReader and XamlWriter with the new XamlServices class. Not only everything worked as expected, some of my problems were gone too. This is what made me to write about the problem.

Back when I first encountered this problem, I was planning to post my solution here. Then, I heard about a new feature in the upcoming System.Xaml.dll and thought I should wait for it. In other words, I was lazy. So here it goes:

Old Problem

Here is a sample file saved by Geostructor v0.3, which targets .NET Framework 3.5 SP1:

Here, RelatedPoint property of RelativePoint is of type IGPoint which inherits INotifyPropertyChanged interface. RelatedPoint objects listen to the PropertyChanged events of the referenced objects. In order to keep these references after saving and loading back, I had to prevent XamlWriter from producing such result:

Old Solution

Continue reading