Developing PixelSense apps with clean XAML using custom namespaces and prefix

As PixelSense developer I love to have my own components declared in some assemblies that I reference in all projects I work.

I also love to have clean XAML file. It's true: for 90% of the time I edit XAML with Blend but there are cases when I use to edit it by typing my own XAML.

Now, if I, or Blend, have to reference my components in XAML, to declare and use my controls I would have a XAML reference like the following:

xmlns=sl:"clr-namespace:Softwarelab.Surface.Presentation.Controls;assembly=Softwarelab.Surface"

 

But.. I would like to have the same assembly declaration of the controls in the Surface SDK

I would love to have my own XAML namespace. Well this is possible, by adding some properties in the AssemblyInfo file of the project containing controls.

Just open the file mentioned above and add the proprerty(ies) needed for your scope:

[assembly: XmlnsPrefix("http://schemas.softwarelab.it/surface/2008", "sl")] 

[assembly: XmlnsDefinition("http://schemas.softwarelab.it/surface/2008", "Softwarelab.Surface.Presentation.Controls")]

Now in your XAML you can declare you assembly in this way:

xmlns:sl="http://schemas.softwarelab.it/surface/2008"

Wow! Great.

There is also another way to reference you controls embed it directly in the Surface SDK controls, if you wold like to see your controls mixed with the one of the SDK just add the following property to you AssemblyInfo:

[assembly: XmlnsDefinition("http://schemas.microsoft.com/surface/2008", "Softwarelab.Surface.Presentation.Controls")]

Now you will see your controls mixed with the controls of the SDK.

Pro of this approach is that once you referenced the Surface SDK controls you don't have to reference any more your controls.

Cons is that all controls are mixed up.

Personally I really like to have my own namespace!

 

Ultimi Post

Discalmer

Articles and content of this blog aren't and shouldn't be interpreted as professional advice or opinions. Author writes on a personal basis and as part of their own research, experimentation and knowledge. Opinions expressed aren't in any way attributable to professional affiliations / institutional thereof or to opinions that the author express as part of their roles / positions that may be quite different from that reported here.