The following code is in a WPF project using NavigationWindow. The code behind has several override methods. In the override below 'favoritesItem' must be accessed. 'favoritesItem' is located in a separate .XAML file. Clearly I am not accessing it properly. This is the override:
Protected Overrides Sub OnClosed(e As EventArgs)
  MyBase.OnClosed(e)
  ' Persist the list of favorites
  Dim f As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
  Using stream As New IsolatedStorageFileStream("myFile", FileMode.Create, f)
    Using writer As New StreamWriter(stream)
      For Each item As TreeViewItem In DirectCast(System.Windows.Application.Current.Properties("favoritesItem"), TreeViewItem).Items
        writer.WriteLine(TryCast(item.Tag, String))
      Next
    End Using
  End Using
End Sub
This error is:
Object reference not set to an instance of an object
What is the proper method to access a XAML element [edited] in a different file?
 
    