first_page

You can’t just open a System.Windows.Controls.Window in any Assembly you like…

I regret not catching up with Chris Sells and his previous push for WPF. Chris has moved on… I was even selected to review one of his books years ago but my horrid commitments to time-consuming programming tasks swamped me. I am almost sure that errors like this:The type 'System.Windows.Markup.IComponentConnector' is defined in an assembly that is not referenced.orThe type 'System.Windows.Markup.IQueryAmbient' is defined in an assembly that is not referenced.The above error is simply saying that I’m trying to open a WPF Window inside of a DLL and not an EXE. Then, there’s this error:The component 'Songhay.Wpf.WordWalkingStick.Views.ClientView' does not have a resource identified by the URI '/Songhay.Wpf.WordWalkingStick;component/views/clientview.xaml'. Amazon.com productThe above error came (past tense) from my WordWalkingStick pet project on CodePlex.com. This boils down to the absence of a facility that associates WPF Window XAML with the WPF “code” (an instance). This facility is associated with WPF EXEs and not WPF DLLs. Visual Studio auto-generates a WPF EXE class called App.g.cs (in your \obj\Debug folder) with this call in it: System.Windows.Application.LoadComponent(this, resourceLocater) where resourceLocater is a badly named variable containing a System.Uri pointing to the XAML like ClientView.xaml mentioned above.

I’m sure Chris Sells has a whole chapter written on how WPF depends on System.Windows.Application for its very life. It is my loss (quite literally of time) for not having read about it.

I have shown myself a little something with this unit test:[STAThread] [TestMethod] public void ShouldOpenWindow() { Application app = new Application(); app.Run(new Window()); }Failing to wrap a new Window in the System.Windows.Application.Run() method will throw an error from the land of COM talking about, “Why did you pull the rug from underneath me?”

Comments

Jesse Seger, 2013-10-04 14:14:40

I came across this problem as well, or you could say even a bigger problem.

Let's say you have a plugin architecture hosted in wpf. If one of my plugin's command was to show a window using the application.run it would show the window. However, when the plugin window was closed, it would also close the main application!

rasx()