Partial Public Class MainPage
Inherits UserControl
' Create the topics collection.
Public Shared Topics As New ObservableCollection(Of Topic)()
Public Sub New()
InitializeComponent()
' Add some topics to the collection.
Topics.Add(New Topic("Using Controls and Dialog Boxes", Guid.NewGuid()))
Topics.Add(New Topic("Getting Started with Controls", Guid.NewGuid()))
Dim DataGridTopic As New Topic("DataGrid", Guid.NewGuid())
DataGridTopic.ChildTopics.Add(New Topic( _
"Default Keyboard and Mouse Behavior in the DataGrid Control", Guid.NewGuid()))
DataGridTopic.ChildTopics.Add(New Topic( _
"How to: Add a DataGrid Control to a Page", Guid.NewGuid()))
DataGridTopic.ChildTopics.Add(New Topic( _
"How to: Display and Configure Row Details in the DataGrid Control", _
Guid.NewGuid()))
Topics.Add(DataGridTopic)
myTreeView.DataContext = Topics
End Sub
Private Sub myTreeView_SelectedItemChanged(ByVal sender As Object, _
ByVal e As RoutedPropertyChangedEventArgs(Of Object)) _
Handles myTreeView.SelectedItemChanged
' Set the data context of the text block to the selected value.
Dim myTreeView As TreeView = TryCast(sender, TreeView)
idTextBlock.DataContext = myTreeView.SelectedValue
End Sub
End Class
' Simple business object.
Public Class Topic
Private titleValue As String
Public Property Title() As String
Get
Return titleValue
End Get
Set(ByVal value As String)
titleValue = value
End Set
End Property
Private idValue As Guid
Public Property Id() As Guid
Get
Return idValue
End Get
Set(ByVal value As Guid)
idValue = value
End Set
End Property
Private childTopicsValue As ObservableCollection(Of Topic)
Public Property ChildTopics() As ObservableCollection(Of Topic)
Get
Return childTopicsValue
End Get
Set(ByVal value As ObservableCollection(Of Topic))
childTopicsValue = value
End Set
End Property
Private Sub New()
ChildTopics = New ObservableCollection(Of Topic)()
End Sub
Public Sub New(ByVal title1 As String, ByVal id1 As Guid)
Me.New()
Title = title1
Id = id1
End Sub
End Class