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

前端 未结 6 1236
陌清茗
陌清茗 2021-02-18 18:54

I copied three classes in from another WPF project and then changed their namespaces.

Now when I run the project, I get errors in the \".g.cs\"

6条回答
  •  臣服心动
    2021-02-18 19:04

    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:

    And then you changed your namespace:

    namespace Baz {
        class Bar { ...
    

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

提交回复
热议问题