Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare array of array in xaml

I'm trying to use an inline data source for a data grid, and obviously XAML supports array of builtin types with x:Array, but when I tried to declare a nested array, tried a few ways but none of them works.

<x:Array Type="{x:Type Array}">
    <x:Array Type="{x:Type x:String}">
        <x:String>aaa1</x:String>
        <x:String>aaa2</x:String>
    </x:Array>
    <x:Array Type="{x:Type x:String}">
        <x:String>aaa9</x:String>
        <x:String>aaa10</x:String>
    </x:Array>
</x:Array>

This wont work either:

<x:Array Type="{x:Type {x:Array Type={x:Type String}}">
like image 201
fluter Avatar asked Dec 24 '22 13:12

fluter


1 Answers

Try this:

<x:Array xmlns:s="clr-namespace:System;assembly=mscorlib" x:Key="array" Type="{x:Type s:Array}">
    <x:Array Type="{x:Type s:String}">
        <s:String>aaa1</s:String>
        <s:String>aaa2</s:String>
    </x:Array>
    <x:Array Type="{x:Type s:String}">
        <s:String>aaa9</s:String>
        <s:String>aaa10</s:String>
    </x:Array>
</x:Array>

Sample usage:

<ItemsControl ItemsSource="{StaticResource array}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <ItemsControl ItemsSource="{Binding}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
like image 149
mm8 Avatar answered Dec 27 '22 22:12

mm8