শনিবার, ১ জানুয়ারী, ২০১১

Extending Xaml and mapping prefix

Extensibility:

The abbreviation of XAML is eXtended Application Markup Language.

One of the important features of XAML is extensibility.

By extensibility feature external elements can be import inside a document without changing any feature.

How to Mapping a Prefix to CLR Namespace:

XAML has a special syntax for define namespace:

xmlns:Prefix=”clr-namespace:Namespace;assembly=AssemblyName”

Here-

· Prefix is the XML prefix you want to use to indicate that namespace in your XAML markup. For example, the XAML language uses the x: prefix.

· Namespace is the fully qualified .NET namespace name.

· AssemblyName is the assembly where the type is declared, without the .dll extension. This assembly must be referenced in your project. If you want to use your project assembly, leave this out.

For example, here’s how you would gain access to the basic types in the System namespace and map them to the prefix sys:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

Example:

Think we need to place a Double value in the documents resources.

So we need to import Double value type document by creating a new xmlns statement because XAML is by default configured for user interface elements and the default namespaces do not map to Double type.

If we see following steps it might be much clearer for us:

  1. Create a new SL4 project named DoubleResoursces
  2. Open Main.XAML
  3. Under User Control / root tag we will type xamlns
  4. Define the prefix
  5. Press =
  6. Select System(mscorlib)
  7. Under UserControl.Resources add a double value resources.

200

100

  1. Finally add a Button within main grid by using the Double value from the resources.

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন