Silverlight Schema Context
The Silverlight Schema Context provided in the XAML toolkit allows inspection of Silveright XAML by tools that process XAML .Net 4.0 node streams. For example: XAML validation in FxCop or loading into a XAML DOM with the XamlDomWriter. The Silverlight Schema Context is not suitable for loading Silverlight content into the .Net 4.0 XamlObjectWriter(). A Silverlight runtime on .Net 4.0 is not available at this time.
Why is there a special Silverlight Schema Context?
The differences between Silverlight and standard XAML are small but problematic. There are several differences. One example is the internal implementation of “Binding” or “StaticResource” are different enough that the standard XAML Schema Context would be confused. So when loading Silverlight content you should use a SilverlightSchemaContext.
Note: “standard XAML” is defined as XAML that System.Xaml would understand using the base class System.Xaml XamlSchemaContext. By that standard WPF XAML has differences from standard XAML as well.
How does one create a Silverlight Schema Context?
Suppose you are writing an application and you are given some XAML to load and a collection of application assemblies that make up some application, and you want to load the assembly XAML into a XamlDOM. The normal XAML code idiom is to create a schema context, a reader, a writer and transform the reader into the writer.
In this example the application assemblies could be WPF or Silverlight so the XAML Toolkit provides a few APIs that help you create the correct Schema Context.
“IsSilverlightAssembly()” will tell you if an assembly is a Silverlight Assembly.
When you have Silverlight application assemblies you should use a SilverlightSchemaContext. To construct a SilverlightSchemaContext you will need have a complete list of reference assemblies including the Silverlight system reference assemblies. Finding the right version of the Silverlight runtime reference assemblies requires knowledge of where Silverlight SDK installs things. The Toolkit provides another API to help with that.
“CreateSilverlightSchemaContext()” will load the correct Silverlight system reference assemblies based on the application assemblies you provide. The system assemblies are combined with your application assemblies and the Silverlight Schema Context is created for you:
Currently we support Silverlight versions: 3, 4 and Phone7.
This feature supersedes the UISchemaContext feature in the previous version of the toolkit.