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 ...

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.