开发者

Old namespace still in .g.cs file when changing namespace of a referenced class

I have renamed the namespace of a referenced class and WPF compiler doesn't want to take it into account: it keeps prefixing MyOldNameSpace in .g.cs file:

[System.CodeDom.Compiler.GeneratedCodeAttribute
     ("PresentationBuildTasks", "4.0.0.0")]
public partial class MyClass: 
    MyOldNameSpace.MyReferencedClass, 
    System.Windows.Markup.ICo开发者_Python百科mponentConnector {

Why ? How to fix this ? What's this obscure .g.cs file ?


Looks like you didn't change your MyClass.xaml file. There should be something like this on top of it

<MyClass x:Class="MyOldNameSpace.MyReferencedClass"

but should be "MyNewNameSpace.MyReferencedClass"


Close the .g.cs file. You can even delete it.

The g stands for generated, VS generates the wireing up between the code and the Xaml in this partial class.

Clean the solution and rebuild. That should fix it.


Don't forget to change your Generic.xaml file too,

<ResourceDictionary 
                   xmlns:local="clr-namespace:MyOldNameSpace">
</ResourceDictionary>


In my case removing obj folder fixed the error.


Also check xmlns:local in Application.xaml. This had me going for a while...


Maybe another case is that the build action of your xaml is not "Page" but the other options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜