次の方法で共有


x:Array Markup Extension

Provides general support for arrays of objects in XAML.

XAML Object Element Usage

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

XAML Values

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.

Remarks

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

In the WPF XAML reader 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 xmlns 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:

<x:Array Type="sys:String" xmlns:x= https://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 reader recognizes that a markup extension must process the attribute. For details on markup extensions in general, see Markup Extensions and XAML.

See Also

Concepts

Styling and Templating
XAML Overview
Markup Extensions and XAML