My goal is to retrieve an ObservableCollection<Color> out of a XAML resource file, but I'm using .NET 3.5 so I can't directly declare the generic type in XAML. My current solutions is to declare a Color array in XAML:
<x:Array Type="Color" x:Key="ColourPickerStandardColours">
<Color>#974806</Color>
<Color>#FF0000</Color>
<Color>#FFC000</Color>
...
<Color>#7030A0</Color>
</x:Array>
and retrieve it in code:
var standardColours = new ObservableCollection<Color>(
(Color[])TryFindResource("ColourPickerStandardColours"));
When I try to run this though, I get this exception:
InvalidCastException
Unable to cast object of type 'System.Windows.Markup.ArrayExtension' to type
'System.Windows.Media.Color[]'.
ArrayExtension has IList Items, but I need the generic IEnumerable<T> to construct an ObservableCollection<T>. I think I could use ProvideValue(IServiceProvider), but I'm not sure what I should pass to it.
Am I doing something wrong, or just missing something obvious?
Items.Cast<Color> ().