开发者

How would I load a WPF MVVM View from an external dll into a WPF application?

开发者 https://www.devze.com 2023-04-11 08:29 出处:网络
I\'m writing an InformationKiosk WPF application that displays different full screen slides (or views), rotating through each one for pre-determined lengths of time. Stage 1 is complete... this enable

I'm writing an InformationKiosk WPF application that displays different full screen slides (or views), rotating through each one for pre-determined lengths of time. Stage 1 is complete... this enables the users to cycle through web pages that they have chosen and works perfectly.

Stage 2 is where I am stuck. I am required to now display slides from external WPF applications (of which I have full code access) and I'm having real problems with this.

I added the other application's dlls as references in the InformationKiosk application, but I got a number of errors because of styles that were not found. I think the problem is that the required view from the other application uses styles from the App.xaml file and an external stylesheet.

I managed to load the styles from the external stylesheet file using the follo开发者_如何转开发wing in a ResourceDictionary.MergedDictionaries element:

<ResourceDictionary Source="pack://application:,,,/ProjectName.Views;component/Support/
SupportQueueItemStyle.xaml" />

The problem is that I can't load the App.xaml file from the other application because we can't have 2 App.xamls in one application. Therefore, when running the application I keep getting the XamlParseException "Set property 'System.Windows.FrameworkElement.Style' threw an exception." (This means that it can't find the styles).

So how is this senario supposed to be implemented in WPF/MVVM? Surely there must be a better way than copying the code from the required views into the InformationKiosk application. I also tried loading the external application assembly using the following code:

Assembly assembly = Assembly.LoadFrom(@".\AssemblyName.exe");

While it loads ok, I couldn't find any useful properties in assembly and don't really know what to do with it and if I can even get what I want using this method.

If you can help, please do. Many thanks.


Make a shared assembly (.dll) We use that for our products and its working very well. We have like 4-5 WPF based shared assemblies. In Visual Studio we just used the "WPF Custom Control Library" instead of an App.xaml you have a Themes/Generic.xaml which will be loaded automatically if you add the reference to your main executable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号