Using Custom Namespaces in Silverlight XAML

<UserControl x: Class="SilverlightApplication1.MainPage" 
  xmlns:abc=" clr-namespace:ClassName; assembly=ClassLibraryName">

The XML namespace declaration sets three pieces of information:
• The XML namespace prefix: You’ll use the namespace prefix to refer to the namespace in your XAML page. In this example, that’s abc, although you can choose anything you want that doesn’t conflict with another namespace prefix.
• The .NET namespace: In this case, the classes are located in the ClassName namespace. If you have classes that you want to use in multiple namespaces, you can map them to different XML namespaces or to the same XML namespace (as long as there aren’t any conflicting class names).
• The assembly: In this case, the classes are part of the ClassLibraryName.dll assembly. (You don’t include the .dll extension when naming the assembly.) Silverlight will look for that assembly in the same XAP package where your project assembly is placed.

Once you’ve mapped your .NET namespace to an XML namespace, you can use it anywhere in your XAML document. For example, if the ClassName namespace contains a control named MyButton, you could create an instance like this:

<abc:MyButton Content="Click Me! " Click="DoSomething"></abc:MyButton>

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.