Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top