F# Silverlight 3.0 Custom Control Property throws: NullReferenceException
- by akaphenom
A new issue since my previous post. I am having some issues with the properties of the control in my Control Class I havse defined:
static member ItemsProperty : DependencyProperty =
DependencyProperty.Register(
"Items",
typeof<MyMenuItemCollection>,
typeof<MyMenu>,
null);
member this.Items
with get () : MyMenuItemCollection = this.GetValue(MyMenu.ItemsProperty) :?> MyMenuItemCollection
and set (value: MyMenuItemCollection) = this.SetValue(MyMenu.ItemsProperty, value);
The problem occurs on access:
for menuItem in this.Items do
let contentElement: FrameworkElement = menuItem.Content
where I get a null referce exception on this.Items;
'Items' threw an exception of type
'System.NullReferenceException'
Immediately after I initialized in the constructor:
do
this.Items <- new CoolMenuItemCollection()