title: wpf - binding datacontext to static properties of singleton class
body: <p>I found myself using a lot of individual bindings to my App class for storage of properties and this led me to a untracable stackoverflow exception.  I've now decided I would move those properties to a separate singleton ApplicationInfo class but I am having some issues with the binding.</p>
  
  <p>If I bind directly to a member property of my class, such as CurrentUser then it works fine. But when I try to bind a datacontext to this class I get compiler errors and I am sure there is some simple modification that i've overlooked.</p>
  
  <p>I've created a singleton out of this class but now when I try to compile I get the error "Unknown build error - key cannot be null" and it points to my Datacontext binding for the error message.</p>
  
  <p>Here's my class:</p>
  
  <pre><code> public class ApplicationInfo
  {
      private ApplicationInfo()
      {
  
      }
      private static ApplicationInfo _Current = new ApplicationInfo();
      public static  ApplicationInfo Current
      {
          get { return _Current; }         
      }
  
      #region Application Info Properties
      private static Assembly _ExecutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();  //holds a copy of this app's assembly info
      public static String ApplicationName
      {
          get { return _ExecutingAssembly.ManifestModule.Name; }
      }
      public static String ApplicationNameTrimmed
      {
          get { return _ExecutingAssembly.ManifestModule.Name.TrimEnd('.', 'e', 'x'); }
      }
      public static String ApplicationPath
      {
          get { return _ExecutingAssembly.Location; }
      }
      public static String ApplicationVersion
      {
          get { return _ExecutingAssembly.GetName().Version.ToString(); }
      }
      public static DateTime ApplicationCompileDate
      {
          get { return File.GetCreationTime(Assembly.GetExecutingAssembly().Location); }
      }
      #endregion
      private static Boolean _hasOpenWindows;
      public static Boolean HasOpenWindows
      {
          get { return _hasOpenWindows; }
          set { _hasOpenWindows = value; }
      }
  
      private static User _currentuser;
      public static User CurrentUser
      {
          get { return _currentuser; }
          set { _currentuser = value; }
      }
      private static Mantissa.DAL _datalayer;
      public static Mantissa.DAL DataLayer
      {
          get { return _datalayer; }
          set { _datalayer = value; }
      }
      private static string _connectionstring;
      public static string ConnectionString
      {
          get { return _connectionstring; }
          set { _connectionstring = value; }
      }
  
  
  
  
  
  }
  </code></pre>
  
  <p>This works:</p>
  
  <pre><code>`Title="{Binding Source={x:Static my:ApplicationInfo.ApplicationNameTrimmed}}"`
  </code></pre>
  
  <p>This does not: (throws the key cannot be null msg)</p>
  
  <pre><code>DataContext="{Binding Source={x:Static my:ApplicationInfo.Current}}"
  </code></pre>
  
  <p>But when I put the same property in my App class then this works:</p>
  
  <pre><code>  DataContext="{Binding Source={x:Static Application.Current}}"
  </code></pre>
  
  <p>so how do I fix this? </p>