title: how do I access a XAML object from a class other than main?
body: <p>If I try "var mainpage new Mainpage()"
  I will run the mainpage constructor and then all the fields in the XAML object will return to null.  How to I access XAML objects in silverlight that are from a different class but part of the same namespace?</p>
  
  <p>Let me explain by example.  If you look at the first answer, here is what I am encountering</p>
  
  <pre><code>public class MyPage
  {
      MyPage()
      {
  
        // the constructor makes all the variables from the xaml null
      }
  
      public TextBox MyTextBox
      {
          get { return SomeTextBox; }
      }
  }
  
  
  public class SomeOtherClass
  {
      private void SomeFunction()
      {
          var page = new MyPage();   // this makes the text empty
          var sometext = page.MyTextBox.Text;   // so sometext will be empty
      }
  }
  </code></pre>
  
  <p>So whatever the user imputs when the program first runs turns to null when I run SomeFunction.</p>
  
  <p>What I am first going to try is to see if when SomeClass is created, the values are put into that class.</p>
  
  <p>If that fails, I am going to try MVVM.  I have seen the <a href="http://www.vimeo.com/8915487" rel="nofollow">http://www.vimeo.com/8915487</a> video and I got the sample mvvm code </p>
  
  <p>Here is the Model:</p>
  
  <pre><code>namespace SimpleMVVM.Model
  {
      public class SimpleModel
      { 
          // super easy version
          //public string SomeSimpleValue { get; set; }
  
          private string _SomeSimpleValue = string.Empty;
  
          // actually do something version...
          public string SomeSimpleValue
          {
              get
              {
                  return "some value";
              }
              set
              {
                  _SomeSimpleValue = value;
              }
          }
      }
  }
  </code></pre>
  
  <p>here is the view:</p>
  
  <p>
      
          
      
      
          
      
  </p>
  
  <p>and here is the viewmodel.cs</p>
  
  <pre><code>using Simple;
  using SimpleMVVM.Model;
  
  namespace SimpleMVVM.ViewModel
  {
      public class SimpleViewModel : SimpleViewModelBase
      {
          private SimpleModel MyModel = new SimpleModel(); 
  
          public string SomeSimpleValue
          {
              get { return MyModel.SomeSimpleValue; }
              set
              {
                  if (MyModel.SomeSimpleValue != value)
                  {
                      MyModel.SomeSimpleValue = value;
                      RaisePropertyChanged("SomeSimpleValue");
                  }
              }
          } 
      }
  }
  </code></pre>
  
  <p>Using this example, I am wondering if it will just as easy as injecting a ViewModel and then changing the bindings in the Model and the View.</p>
  
  <p>Is MVVM really this easy?</p>
  
  <p>There is one more.  It is the viewmodel base class</p>
  
  <pre><code>using System.ComponentModel;
  
  namespace Simple
  {
      public class SimpleViewModelBase : INotifyPropertyChanged
      { 
          public event PropertyChangedEventHandler PropertyChanged;
  
          public void RaisePropertyChanged(string PropertyName)
          {
              var e = new PropertyChangedEventArgs(PropertyName);
              PropertyChangedEventHandler changed = PropertyChanged;
              if (changed != null) changed(this, e);
          }
      }
  }
  </code></pre>
  
  <p><strong>OK, so now the hard part.  If I create a new class.  How do I get the data from the viewmodel class?</strong></p>