Any ItemsSource more complicated than int[] is very difficult to define in XAML. I would just do it in the code-behind.
Multi-Value XAML Array

In the ItemsSource property of a CollectionView I want to place an array of an anonymous type or Tuple. Visual Studio 2019 Intellisense lets me do the following:
<CollectionView.ItemsSource>
<x:Array Type="{x:Type system:(T1, T2)`2}">
</x:Array>
</CollectionView.ItemsSource>
However, I am not sure what to do next. How do I put the data in the array, and how do I specify names (or if it is a Tuple, do I just use the default names of Item1, Item2, etc.)? I know that I could create a temporary class instead, but because this is for design time / testing only I would prefer not to do that. What should I do next, or where can I find more about Type="{x:Type system:(T1, T2)`2}"? Thanks!
@Nathan Sokalski Because Xamarin.Forms XAML provides support for consuming generic CLR types by specifying the generic constraints as type arguments, So if you wirte code in the XAML, Intellisense will give you feasible way that add value to
ItemsSource
in XAML, not in the C# background code. If you want to write this type ofItemsSource
, you can refer to this article.https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/generics
The ItemsSource on that page is not quite what I was looking for. I was looking for anonymous types, that page uses actual classes, such as KeyValuePair & Monkey.
@Nathan Sokalski If you want to create anonymous types and Key-Value type dynamically. Please follow jcmanke's advice create it in the backgroud code with
Dictionary
like following code format in the ViewModel. Then bind it to your layout.Sign in to comment