I'm calling this from a non-UI thread (another thread than my WPF controls) :
public static FontFamily GetDefaultFontFamily()
{
FontFamily fontFamily = null;
Application.Current.Dispatcher.Invoke(
new Action(
delegate
{
fontFamily = new TextBlock().FontFamily;
}));
return fontFamily;
}
but Application.Current
is null
in my case (WPF objects hosted in MFC app)...
The only solution is to pass as a parameter a DispatcherObject
instance, but this causes many modifications elsewhere, and makes it not a clean s开发者_如何转开发olution from the calling code.
Any ideas ?
I got around the problem by making the class store a valid reference to a dispatcher the first time the class is used (made it a singleton too).
Not the best solution, but its the less worse...
精彩评论