How to use Prism within an ElementHost

后端 未结 2 880
耶瑟儿~
耶瑟儿~ 2020-12-20 06:24

I\'m new to Prism and I am attempting to host a Prisim control within an ElementHost. I seem to be missing something very basic. I have a single WinForm that contains an El

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 06:39

    The reason is this code in Prism:

    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!

    The solution:

    1. Create an empty class that will inherit from System.Windows.Application. (Name doesn’t matter):

    At the point of entry to a plug-in execute the following code:

    public class MyApp : System.Windows.Application
    {
    }
    
    if (System.Windows.Application.Current == null)
    {
        // create the Application object
        new MyApp();
    }
    

    This is it – now you have an Application.Current that is not null and it’s not equal to typeof(Application).

提交回复
热议问题