Imports C1.Silverlight.Extended

Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()

        ' add a custom editor to edit nested Address field
        c1pg.AvailableEditors.Insert(0, New AddressEditor())

        Dim p As New Person() With {.ContactInfo = New Address() With {.country = "Country", .street = "Street", .zip = 123}, .FirstName = "Name"}

        c1pg.SelectedObject = p

    End Sub

End Class

Public Class AddressEditor
    Inherits C1Expander
    Implements ITypeEditorControl

    Public Function Supports([Property] As C1.Silverlight.Extended.PropertyAttribute) As Boolean Implements C1.Silverlight.Extended.ITypeEditorControl.Supports
        Return [Property].PropertyInfo.PropertyType.IsAssignableFrom(GetType(Address))
    End Function

    Public Sub Attach([Property] As C1.Silverlight.Extended.PropertyAttribute) Implements C1.Silverlight.Extended.ITypeEditorControl.Attach
        Dim editor = New C1PropertyGrid()
        editor.SelectedObject = TryCast([Property].SelectedObject, Person).ContactInfo
        Me.Content = editor
    End Sub

    Public Function Create() As C1.Silverlight.Extended.ITypeEditorControl Implements C1.Silverlight.Extended.ITypeEditorControl.Create
        Return New AddressEditor()
    End Function

    Public Sub Detach([Property] As C1.Silverlight.Extended.PropertyAttribute) Implements C1.Silverlight.Extended.ITypeEditorControl.Detach

    End Sub

    Public Event ValueChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements C1.Silverlight.Extended.ITypeEditorControl.ValueChanged

End Class

Public Class Person

    Public Property FirstName As String
        Get
            Return m_FirstName
        End Get
        Set(value As String)
            m_FirstName = value
        End Set
    End Property

    Public Property ContactInfo As Address
        Get
            Return m_ContactInfo
        End Get
        Set(value As Address)
            m_ContactInfo = value
        End Set
    End Property

    Private m_FirstName As String
    Private m_ContactInfo As Address
End Class

Public Class Address

    Public Property country As String
        Get
            Return m_country
        End Get
        Set(value As String)
            m_country = value
        End Set
    End Property

    Public Property street As String
        Get
            Return m_street
        End Get
        Set(value As String)
            m_street = value
        End Set
    End Property

    Public Property zip As Integer
        Get
            Return m_zip
        End Get
        Set(value As Integer)
            m_zip = value
        End Set
    End Property

    Private m_country As String
    Private m_street As String
    Private m_zip As Integer
End Class