Suppose I have a normal Xaml file with two extra xmlns, one to a “Person” Class with two CLR properties “Name” and “Age”, and one to a String object:
<Window x:Class="WpfPractice.ListBinding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfPractice"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="ListBinding" Height="200" Width="600">
I can place an array of strings in the Resources collection of my root window element:
<Window.Resources>
<x:Array x:Key="ThisWorks" Type="{x:Type sys:String}">
<sys:String>John</sys:String>
<sys:String>Andy</sys:String>
</x:Array>
</Window.Resources>
I can also instantiate an object in the resources of the root control:
<Window.Resources>
<local:Person x:Key="ThisAlsoWorks" Name="Michael" Age="40"/>
</Window.Resources>
But VS won’t let me build if I instantiate an array of ojects in the resources of the root control:
<Window.Resources>
<x:Array x:Key="ThisWontBuild" Type="{x:Type local:Person}">
<local:Person Name="Michael" Age="40"/>
<local:Person Name="Jim" Age="30"/>
</x:Array>
</Window.Resources>
Howwver VS will build if I instantiate the array of ojects in the resources of a child control such as a grid:
<Grid.Resources>
<x:Array x:Key="ThisWillBuild" Type="{x:Type local:Person}">
<local:Person Name="Michael" Age="40"/>
<local:Person Name="Jim" Age="30"/>
</x:Array>
</Grid.Resources>
Anybody know why?
Maybe you were lacking the respective
xmlnson the root element?I cannot think of any other reason why it would not work and i can tell you that it is certainly possible as i do that quite frequently.