title: Setting attached property in App.xaml
body: <p>I have the following app.xaml:</p>
  
  <pre><code>&lt;BaseApp x:Class ="MyApp"
           xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:local ="clr-namespace:MyApp"
          Props.MyCustom="test"
           Startup ="Application_Startup"                                 
           &gt;
  
  &lt;Application.Resources &gt;
      &lt; ResourceDictionary&gt;
          ...
      &lt;/ ResourceDictionary&gt;        
  
  &lt;/Application.Resources&gt;   
  </code></pre>
  
  <p></p>
  
  <p>I then need to be able to read the property from the base application:</p>
  
  <pre><code> public partial class BaseApp : Application
  {        
  
        static void MyFunc()
        {
             // Access property from here
             var myvar = Props.MyCustom
        }
  }
  </code></pre>
  
  <p>I'm currently working on the belief that this needs to be in a separate class, as follows:</p>
  
  <pre><code> public class Props : DependencyObject
  {
      public string MyCustom
      {
          get { return ( string)GetValue(MyCustomProperty); }
          set { SetValue(MyCustomPropertyKey, value); }
      }
  
      public static readonly DependencyPropertyKey MyCustomPropertyKey =
          DependencyProperty.RegisterAttachedReadOnly("MyCustom" , typeof (string ), typeof (Props), new UIPropertyMetadata (0));           
  
      public static readonly DependencyProperty MyCustomProperty = MyCustomPropertyKey.DependencyProperty;
  
  }
  </code></pre>
  
  <p>Am I approaching this in the right way, and if so, what do I need to do to be able to access this from app.xaml?</p>
  
  <p>EDIT:</p>
  
  <p>For future travellers, the way I finally managed this was to simply declare an abstract read-only property in the base class and override it in code behind.  Not as neat as I would have liked, but it works.</p>