Tuesday, May 22, 2007

Accociate schema to custom namespaces

If we analyze a xaml file we could see 2 lines at the beggining.

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

These lines map the namespaces to xaml file.Whenever we need to refer our own custom dll we often use the following format .

xmlns:mycontrols="clr-namespace:MyControls;assembly=MyControls"

We could also use the URL type mapping for our own controls.For this we need to include the following 3 lines in the Assemblyinfo.cs file of our custom dll.

  • Add a reference to using System.Windows.Markup;
  • Add 2 attributes

[assembly: XmlnsPrefix("http://schemas.joymon.com/mycontrols", "mycontrols")]
[assembly: XmlnsDefinition("http://schemas.joymon.com/mycontrols", "MyControls")]

Now you could use like the following in your xaml file to refer custom dll

xmlns:mycontrols="http://schemas.joymon.com/mycontrols"

A sample here

No comments:

Post a Comment