views:

400

answers:

2

I have a WPF UserControl with binding converters referenced like this:

<UserControl x:Class="MyControl" x:Name="MyControl"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:local="clr-namespace:TheMainNamespaceOfThisAssembly">

    <UserControl.Resources>
      <local:ConfidenceColorConverter x:Key="ConfidenceColorConverter"/>
    </UserControl.Resources>

I then use the binding converter later. I see the user control in my design window. Then I compile, then place this user control in my main window. I run it and it works. However, I still would like to use the designer on the main window, which breaks with:

Could not create an instance of type 'MyControl'.

So I learned how to debug the designer; when I do, I get an XamlParseException:

Cannot find type 'TheMainNamespaceOfThisAssembly.ConfidenceColorConverter'. The assembly used when compiling might be different than that used when loading and the type is missing. Error in markup file...

If remove the references to the converters, my user control displays well in the designer on the main window. Any ideas how to fix my references to the converters so that they won't break the designer?

Couldn't understand if the article Troubleshooting WPF Designer Load Failures applies or not.

+1  A: 

Could you please try to reproduce the problem on a clean new project rather than editing your existing one? You cannot have

<UserControl x:Class="MyControl" x:Name="MyControl"...

as you would need to add a namespace to "x:class" and change "x:Name" value to be different from class name. The designer works fine when I create a clean project as you describe and fix this sort of errors. You might be omitting some details from the question you think are unimportant, but those details can make all the difference.

Stanislav Kniazev
Try using a naming convention in which private fields and XAML keys are camelCase and classes and types are PascalCase.
Danny Varod
@Danny Varod - Huh?
Stanislav Kniazev
I tried changing the x:name to "thisControl" while keeping MyControl as the class name. I tried creating a new project with a converter as a resource used on a binding inside a user control, and the user control used in a Window. That indeed works as Stanislav says. I then simplified my Window and user control in the original project to nothing but the namespaces and XAML needed (matching the near-empty test project), and I still get the error. I'm about to rip out the code-behind of the user control down to a bare minimum.
Patrick Szalapski
Thanks for your help and I'd be happy to post omitted details if I knew what they could be.
Patrick Szalapski
Well, I cannot figure it out. The test project works, but the actual project doesn't. Don't know what other differences to try changing.
Patrick Szalapski
A: 

After talking with others, the VS2008 designer has numerous problems that prevent its use in many situations. We gave up.

Patrick Szalapski