Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

Closed Issue: Region manager in V2 fails to recognize non-WPF applications [3552]

$
0
0
In the recent change of Prism (V2) you've changed how the Region Manager detects that it's running in a Design Mode or not. This has ultimatly broke all my Prism plug-ins that were hosted by non-WPF applications. One of the examples of hosts for such plug-ins is an Office AddIn.
 
It took me about 6 hours to track down this problem and, to my amazement, I've found the place where it broke:
 
private static bool RegionManager::IsInDesignMode(DependencyObject element)
{
// Due to a known issue in Cider, GetIsInDesignMode attached property value is not enough to know if it's in design mode.
return DesignerProperties.GetIsInDesignMode(element) || Application.Current == null
|| Application.Current.GetType() == typeof(Application);
}
 
The reason is that for the non-WPF application the Application.Current is NULL !!!
 
======
Here is the solution, I've found, for my problem, but, I think, the check in RegionManager::IsInDesignMode has to be fixed:
 
1. Create an empty class that will inherit from System.Windows.Applicatoin. (Name doesn't matter):
 
public class MyApp : Application
{
}
 
2. At the point of entry to a plug-in execute the following code:
 
if (System.Windows.Application.Current == null)
{
// create the Application object
new MyApp();
}
 
--> This is it - now you have an Application.Current not null and it's not equal to typeof(Application)
 
If, by any chance you'd like to merge your application resources - do this:
 
// merge in your application resources
System.Windows.Application.Current.Resources.MergedDictionaries.Add(
System.Windows.Application.LoadComponent(
new Uri("MyLibrary;component/Resources/MyResourceDictionary.xaml",
UriKind.Relative)) as ResourceDictionary);
 
For more information check DR.WPF's article (http://www.drwpf.com/blog/Home/tabid/36/EntryID/10/Default.aspx) that beautifuly explains the reasons and workarounds for the problem, described above.
Comments: Fixed in Prism 5.0.

Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>