F# Silverlight 3.0 Custom Control Property throws: NullReferenceException

Posted by akaphenom on Stack Overflow See other posts from Stack Overflow or by akaphenom
Published on 2010-05-18T18:26:20Z Indexed on 2010/05/18 18:30 UTC
Read the original article Hit count: 411

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()

© Stack Overflow or respective owner

Related posts about F#

Related posts about custom-controls