I have a class which is referenced in multiple views, but I would like there to be only one instance of the class shared among them. I have implemented my class like so:
using System;
public class Singleton
{
private static Singleton instance;
private Singleton() {}
public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
Is there a way I can add Singleton.Instance to my resource dictionary as a resource? I would like to write something like
<Window.Resources>
<my:Singleton.Instance x:Key="MySingleton"/>
</Window.Resources>
instead of having to write {x:static my:Singleton.Instance}
every time I need to reference it.