wpf - Adding a static object to a resource dictionary -


i have class referenced in multiple views, there 1 instance of class shared among them. have implemented class so:

using system;  public class singleton {    private static singleton instance;     private singleton() {}     public static singleton instance    {              {          if (instance == null)          {             instance = new singleton();          }          return instance;       }    } } 

is there way can add singleton.instance resource dictionary resource? write like

<window.resources>     <my:singleton.instance x:key="mysingleton"/> </window.resources> 

instead of having write {x:static my:singleton.instance} every time need reference it.

the accepted answer wrong, totally possible in xaml.

<!-- assuming 'my' namespace contains singleton --> <application.resources>    <x:staticextension member="my:singleton.instance" x:key="mysingleton"/> </application.resources> 

Comments