Helpful Hint: Replace xmlns:my with xmlns:csla when dragging controls from VS toolbox

Helpful Hint: Replace xmlns:my with xmlns:csla when dragging controls from VS toolbox

Old forum URL: forums.lhotka.net/forums/t/9265.aspx


GregDobbs posted on Friday, July 23, 2010

If you're like me and prefer a nice namespace declaration at the top of your XAML for CSLA, here's a quick and minor change to the framework that'll do it.

You will need to add a few lines of code near the top of the AssemblyInfo.cs files in four projects in the CSLA framework (added lines are bold):

 

CSLA     AssemblyInfo.cs

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Markup; // added by dobbs to support XmlnsDefinition

// dobbs modification - Added XMLDefinition and XMLPrefix assembly information.
// This allows designers to use the csla: prefix in XAML rather than the generic
// my: prefix.
//Namespaces:
[assembly: XmlnsDefinition("
http://schemas.lhotka.net/dobbs", "Csla")]
// dobbs Prefix:
[assembly: XmlnsPrefix("
http://schemas.lhotka.net/dobbs", "csla")]

// General Information about an assembly is controlled through the following ...

 

CSLA.Silverlight     AssemblyInfo.cs

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Markup; // added by dobbs to support XmlnsDefinition

// dobbs modification - Added XMLDefinition and XMLPrefix assembly information.
// This allows designers to use the csla: prefix in XAML rather than the generic
// my: prefix.
//Namespaces:
[assembly: XmlnsDefinition("
http://schemas.lhotka.net/dobbs", "Csla")]
[assembly: XmlnsDefinition("
http://schemas.lhotka.net/dobbs", "Csla.Silverlight")]
// dobbs Prefix:
[assembly: XmlnsPrefix("
http://schemas.lhotka.net/dobbs", "csla")]

// General Information about an assembly is controlled through the following  ...

 

CSLA.XAML     AssemblyInfo.cs

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Markup; // added by dobbs to support XmlnsDefinition

// dobbs modification - Added XMLDefinition and XMLPrefix assembly information.
// This allows designers to use the csla: prefix in XAML rather than the generic
// my: prefix.
//Namespaces:
[assembly: XmlnsDefinition("
http://schemas.lhotka.net/dobbs", "Csla.Xaml")]
// dobbs Prefix:
[assembly: XmlnsPrefix("
http://schemas.lhotka.net/dobbs", "csla")]

// General Information about an assembly is controlled through the following ...

 

CSLA.XAML.Silverlight     AssemblyInfo.cs

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Markup; // added by dobbs to support XmlnsDefinition

// dobbs modification - Added XMLDefinition and XMLPrefix assembly information.
// This allows designers to use the csla: prefix in XAML rather than the generic
// my: prefix.
//Namespaces:
[assembly: XmlnsDefinition("
http://schemas.lhotka.net/dobbs", "Csla.Xaml")]
// dobbs Prefix:
[assembly: XmlnsPrefix("
http://schemas.lhotka.net/dobbs", "csla")]

// General Information about an assembly is controlled through the following ...

 

Once you've completed the above changes, when you drag a CSLA control onto a XAML control you'll get a xmlns declaration similar to the following at the top of your XAML:

xmlns:csla="http://schemas.lhotka.net/dobbs"

And when you drag a control onto the design surface it'll be prefixed like so (example - a PropertyStatus control):

<csla:PropertyStatus HorizontalAlignment="Left" Margin="5,0,0,0" ...

Obviously you can change all the /dobbs stuff above to your own company name.

And if we're lucky Rocky will put this in the next release and make it all perfect! :-)

Disclaimer: I only put this in yesterday - working great so far - but let me know if you find any issues!

RockfordLhotka replied on Friday, July 23, 2010

That's very cool - thanks for the post! Yes, I'll add this to the wish list, as this is a great idea.

Copyright (c) Marimer LLC