6

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}}">
3
  • " A Type parameter value does not need to use an x:Type markup extension;" Have you tried to write Type="{x:Array}"? Commented Oct 13, 2017 at 10:07
  • @Rebecca yes I tried it, it compiles ok but nothing shows in the listview Commented Oct 13, 2017 at 10:11
  • Its work for me in Xamarin.Forms application. Xamarin.Forms xaml colors array. Commented Jan 17, 2019 at 20:10

1 Answer 1

13

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>
Sign up to request clarification or add additional context in comments.

4 Comments

This wont compile :(
It surely does - in WPF. Which is the tag you have marked your question with.
Ok, vs just failes with value cannot be null, I will try again.
Copy the array above into <Window.Resources>. It works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.