0

I have a XAML/cs class (EditorWindow) that derives from Window and implements some special functions. I also have a subclass in just a .cs file that derives from EditorWindow (public class DetailedEditorWindow:EditorWindow).

If both of these are in the same project, I can open the DetailedEditorWindow just fine (it makes no difference if they are in different namespaces), but if I move DetailedEditorWindow to another project which references EditorWindow, I get a resource missing SystemException - saying it misses the EditorWindow.xaml.

Why is this and how can I fix this error?

Thank you in advance, JasonX

JasonX
  • 503
  • 7
  • 21

1 Answers1

1

Well it happens because EditorWindow is a partial class and can not work only with .cs it needs xaml code to function. When you put DetailedEditorWindow in external assembly and create an instance it will call EditorWindow constructor as well. But this will try to find XAML file which is internally referenced with a local resource Uri. This Uri can't be resolved in your seccond project. I don't think that you can do something about it.

You can see this reference inside .csproj file:

<Compile Include="MainWindow.xaml.cs">
  <DependentUpon>MainWindow.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>

In this case you can create a window without XAML and implement your logic inside. And then Inherit EditorWindow and DetailedEditorWindow from it. However you wont be able to reference Xaml controls by their names.

Another possibility is to use a custom control+style that will implement all the logic and yous window will just host this control.

Dmitry
  • 2,033
  • 1
  • 22
  • 31
  • I was afraid of this... I posted a similar question a few hours back (now deleted) and there was some talk about settings URIs to absolute paths (from local to... global? It was something about pack URIs) but I couldn't find a way to change the reference URI. Could this be possible? – JasonX Apr 13 '14 at 21:49
  • you can try to play with your csproj file and to set a full uri instead of just the xaml file name. But I am almost sure that the uri is set at compile time. – Dmitry Apr 13 '14 at 21:55
  • Well... shoot. The shared methods have stuff to do with the XAML controls (moving, deleting etc.), that's mainly why I'm extending EditorWindow. Tried playing with the EditorWindow project .csproj, no success. Is there really no other way than redesigning most of the app? (The question is dumbed down, there's a LOT more code there). – JasonX Apr 13 '14 at 22:12
  • That's the reaon why UserControls should be avoided as much as possible. It maks development easier to some extent but reduces all possibilities of extention. I think in your case you can define EditorWindow as a cs class with a template and then just inherit. This is not that much of code. You will only need to use GetTempteChild method to retrieve your UI controls. – Dmitry Apr 13 '14 at 22:20
  • Ended up doing just that, and I was able to "hardwire" XAML controls to empty control variables in EditorWindow, so no more than MainCanvas=mainCanvas was required for all the events etc. to work. THANK YOU! You saved me about a day's worth of work :D – JasonX Apr 13 '14 at 23:10