Using DataWindow in 3.0

Mar 16, 2012 at 6:31 PM

I'm updating a working Silverlight project to Catel 3.0 by following the conversion guide in the documentation but I've run into a snag with DataWindow.  It feels like something simple that I've got wrong but I'm stuck.

I've updated my XAML in manner similar to that of UserControls:

<Catel:DataWindow x:Class="Project.Dialogs.ChildDialog">
</Catel:DataWindow>

Similarly, my code behind was reduced to the following:

namespace Project.Dialogs
{
    public partial class ChildDialog : Catel.Windows.DataWindow { }
}

Now when I build, the code generated from the XAML doesn't contain the using statements necessary to find DataWindow:

public partial class ChildDialog : DataWindow { }

"Error 1 The type or namespace name 'DataWindow' could not be found (are you missing a using directive or an assembly reference?)"

Any thoughts?

Mar 17, 2012 at 8:31 AM
Edited Mar 17, 2012 at 8:33 AM

This is a "known bug" in Silverlight (although not many people are aware of it). What you need to do are the following steps:

  1. Remove the catel namespace in the xaml
  2. Save the page
  3. Add the catel namespace again
  4. Save the page

Issue solved. Sometimes, Silverlight cannot translate the xaml into the generated code behind (yes, it will generated a designer code-behind file for the xaml) into the right namespaces. Really annoying, but we cannot do anything about it (it happens with all libraries that use an url as xaml namespace).

Update: you did add the following namespace, right:

xmlns:catel="http://catel.codeplex.com"

Mar 19, 2012 at 2:39 PM
Edited Mar 19, 2012 at 2:46 PM

Yes, I had the namespace already; this is an upgrade to 3.0.

Unfortunately, removing the namespace and adding it back did not resolve the issue.

Update: If I add a UserControl to the DataWindow, the generated code-behind doesn't have a problem (declares a Catel.Windows.Controls.UserControl) but still fails on the DataWindow itself.

Mar 19, 2012 at 2:41 PM

You did save in-between the steps? It *should* work. Otherwise, try a full solution clean and rebuild.

Mar 19, 2012 at 2:50 PM

I did save in-between.  I've even cleaned, closed Visual Studio, and removed the output directory between steps.

Mar 19, 2012 at 8:02 PM

To the best of knowledge from experimenting, this is a Silverlight 5 issue.  Starting with new projects and adding only a DataWindow, it works if the project targeted Silverlight 4 but fails if targeted Silverlight 5.

Mar 19, 2012 at 8:59 PM

Steps to reproduce success:

  1. Create a new project using the Silverlight Application with Catel template (3.0).
  2. Choose Silverlight 4.
  3. Add Catel.MVVM, Catel.Core, and Catel.Extensions.Controls packages with NuGet.
  4. Add a DataWindow and DataWindowModel using the templates from Catel 3.0.
  5. Build succeeds.

Steps to reproduce failure:

  1. Create a new project using the Silverlight Application with Catel template (3.0)
  2. Choose Silverlight 5.
  3. Add Catel.MVVM, Catel.Core, and Catel.Extensions.Controls packages with NuGet.
  4. Add System.Windows.Controls manually.
  5. Add a DataWindow and DataWindowModel using the templates from Catel 3.0.
  6. Build fails.  Type or namespace name 'DataWindow' could not be found.

 

Mar 20, 2012 at 11:01 AM

Thanks! I am very busy at the moment, but I will investigate this at the end of this week.

Mar 20, 2012 at 3:34 PM

I appreciate your time.  Unfortunately, using the Catel 3.0 assemblies causes even the old "intermediate" method to fail during XAML complication, claiming the intermediate class is not in the namespace.  So I'm pretty stuck right now.  :)

Mar 20, 2012 at 3:50 PM

I think you should re-check whether you are linking to the right libraries. Visual Studio has a habit of "fixing" your reference to the output folder (so you *think* you replaced the libraries, but that's not the case).

You can always choose to use a reference the old way:

xmlns:catelwindows="clr-namespace:Catel.Windows;assembly=Catel.MVVM"

Mar 20, 2012 at 3:55 PM

I tried using that namespace directly without success.

For what it's worth, using the Object Browser shows that in SL4, DataWindow inherits from System.Windows.Controls.ChildWindow.  In SL5 it inherits from System.Windows.Window.  Is that significant?

Mar 20, 2012 at 3:58 PM

No, my version of the SL5 also inherits from ChildWindow (double checked via Reflector). Are you sure you didn't accidentally used the NET40 assembly instead of the SL5 one?

Mar 20, 2012 at 4:09 PM

Okay, it looks like the Object Browser was finding the net40 version because somehow my .Web project referenced it.  I cleaned that up but it had no impact on the client project.  Sorry for that confusion.

Mar 20, 2012 at 4:27 PM

No problem, I found the issue. Catel references the old 4.0 SL toolkit (since there simple is no SL5 toolkit on nuget). We will fix it this week and release a patch for SL5...

Mar 20, 2012 at 7:49 PM

We are currently pushing a hotfix (version 3.0.1) which fixes this issue. Both via NuGet and the download page.

Mar 20, 2012 at 7:52 PM

Thank you!