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

Declaring Arrays

WPF supports declaring arrays in XAML with the use of x:Array. For example, the following is a three-element array of strings:

<x:Array Type="{x:Type sys:String}"         xmlns:sys="clr-namespace:System;assembly=mscorlib">  <sys:String>1</sys:String>  <sys:String>2</sys:String>  <sys:String>3</sys:String></x:Array>

x:Array’s Type property must be set to the type of the array, so the XAML snippet leverages x:Type to do so. When the type doesn’t belong in the default XML namespace, it must be qualified with an appropriate XML namespace prefix (sys in this example).

As a shortcut, you could instead specify the Type value as follows:

<x:Array Type="sys:String" xmlns:sys ...

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