After changing namespace in UserControl files, ...g.cs files get errors

The .g.cs file is generated from the .xaml file. You need to change the x:class= attribute in your .xaml file to match the new namespace-qualified class name; then the .g.cs will be generated correctly on next compile. (Don't manually change the .g.cs file -- you'll only frustrate yourself.)

For example, if you previously had this in your .cs:

namespace Foo {
    class Bar { ...

and this in your .xaml:

<UserControl x:Class="Foo.Bar" ...

And then you changed your namespace:

namespace Baz {
    class Bar { ...

Then you would need to change your .xaml file to:

<UserControl x:Class="Baz.Bar" ...

Another possible cause is if you have any xmlns:xx namespaces in your xaml which you neglected to update when changing a namespace, then this will also cause an invalid using statement in the g.cs file.

Tags:

Wpf