O'Reilly logo

XAML Unleashed by Adam Nathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Full Generics Support

In XAML2006, the root element can be an instantiation of a generic class, thanks to the x:TypeArguments keyword. x:TypeArguments can be set to a type name or a comma-delimited list of type names. But because x:TypeArguments can only be used on the root element, generic classes generally have not been XAML friendly.

A common workaround for this limitation is to derive a nongeneric class from a generic one simply so it can be referenced from XAML, as in the following example:

C#:

namespace MyNamespace{  public class Photo { ... }  public class PhotoCollection : ObservableCollection<Photo> { ... }}

XAML:

<custom:PhotoCollection xmlns:custom="clr-namespace:MyNamespace ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required