3

I've been unable to make this work because of what I believe is a glitch in Visual Studio, so I'd really appreciate if someone could attempt this situation and share what happens.

I have setup in a solution 2 projects: - a C++ application which has been CLI enabled (.exe) - a C#/WPF class library which has a .xaml form inside with a matching .cs window class (.dll)

I want to spawn the WPF window inside my C++ application, so I import its reference and create a new instance of the window and run under a new application context. Thats works fine.

I now want to make classes out of this window and handle different events inherited from protected functions in the C# window, so In the C++ assembly make a public ref class whom child is the .cs class of the .xaml powered window. This compiles fine.

ie:

public ref class myCPPWindow : myWPFWindow { ... };

I then change the window I spawn to the parent class which is located in the C++ assembly rather than the base class located in the C# assembly. Now I get an error on the InitializeComponent() part of the base C# class while loading the .xaml window that I require saying that it fails to load the .xaml window source from the C# assembly even though the base class works. Can anyone give an explanation/fix for this?

kvanbere
  • 3,289
  • 3
  • 27
  • 52
  • Still looking for an answer/advice – kvanbere May 03 '12 at 08:15
  • Take a look into the myWPFWindow.xaml.cs and check what resource is loaded and how it's done. Maybe this helps you. – Felix K. May 11 '12 at 11:17
  • It's loaded normally using InitializeComponent(). Nothing special is being done. I've tried moving InitializeComponent to the child instead of the parent and it makes no difference in the failure of locating the form with a relative URI inside InitializeComponent(). – kvanbere May 12 '12 at 12:34
  • Is the assembly included in the URI? – Felix K. May 12 '12 at 21:36
  • Yes, doing so gives a "Absolute URI not supported" error. – kvanbere May 13 '12 at 03:07
  • It looks like a common [library;user control]-[application;derived control] issue in WPF - I reproduced that without C++. Without digging into explanation, general workaround is either aggregating "base" class or re-degisning base class to be templated control instead of user control (e.g. without .xaml file). If I understand correctly, your question is the same as http://stackoverflow.com/questions/7646331/the-component-does-not-have-a-resource-identified-by-the-uri – mikalai May 17 '12 at 14:02
  • Thankyou! This is great, It's EXACTLY my problem! If you still want the bounty post an answer. – kvanbere May 18 '12 at 06:16
  • @kvanberendonck here you are :) – mikalai May 18 '12 at 10:29

1 Answers1

1

It looks like a common [library;user control]-[application;derived control] issue in WPF - I reproduced that even without C++. Without digging into explanation, general workaround is either aggregating "base" class or re-degisning base class to be templated control instead of user control (e.g. without .xaml file). If I understand correctly, your question is the same as The component does not have a resource identified by the uri question.

Community
  • 1
  • 1
mikalai
  • 1,746
  • 13
  • 23
  • Not sure how, but if there is a possibility to indicate a link between questions, that would be helpful. – mikalai May 18 '12 at 10:28