Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

x:Array Markup Extension

Provides general support for arrays of objects in XAML.

<object>
  <object.property>
    <x:Array Type="typeName">
      <arrayObject1/>
      <arrayObject2/>
      ...
    </x:Array>
  </object.property>
<object>

typeName

The name of the type that your x:Array will contain, which often requires a prefix. See Remarks.

arrayObject1arrayObject2, etc.

Object elements that define the contents of your array. See Remarks.

Type is a required attribute for all x:Array object elements.

In the WPF XAML processor implementation, the handling for this markup extension is defined by the ArrayExtension class. This class is not sealed, and could be used as the basis for a markup extension implementation for a custom array type.

x:Array is more intended for general language extensibility in XAML. But x:Array can also be useful for populating certain properties using XAML that take general collection support interfaces or classes as their structured property content, for instance as IEnumerable.

Typically, the object elements that populate an x:Array are not elements that exist in the WPF XML namespace, and will require a prefix mapping.

For example, the following is a simple array of two strings, with the sys prefix (as well as x) defined at the level of the array:

[xaml]

<x:Array Type="sys:String" xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

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

<sys:String>Hello</sys:String>

<sys:String>World</sys:String>

</x:Array>

For more information, see Markup Extensions and XAML and XAML Namespaces and Namespace Mapping. The array elements must also support the requirements for being instantiated in XAML as object elements. For details, see XAML and Custom Classes.

x:Array is a markup extension. Markup extensions are typically implemented when there is a requirement to escape attribute values to be other than literal values or handler names, and the requirement is more global than just putting type converters on certain types or properties. x:Array is somewhat of an exception to that general rule, because instead of providing alternative attribute value handling, x:Array provides alternative handling of its inner text content. This provides support such that element classes that might not be supported by any existing content model can be grouped into an array, and can be referenced later in code-behind by accessing the named array and calling array methods to get individual array items.

All markup extensions in XAML use the { and } characters in their attribute syntax, which is the convention by which a XAML processor recognizes that a markup extension must process the attribute. For details on markup extensions in general, see Markup Extensions and XAML.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.