5

When I modify the xaml's cs's I will have to go in and manually modify the corresponding *.g.cs file. And it seems to get overwritten every time I rebuild.

So my question is, what is the proper way to change the namespace on a WPF application that has been generated by the WPF project template?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Kwan Cheng
  • 696
  • 3
  • 12
  • 16

1 Answers1

17

Since the .g.cs files are generated from the .xaml files, besides changing the namespace in the .xaml.cs files, you also have to change the namespace in the .xaml files.

For example, the main window in one of my projects is declared like this in mainwindow.xaml:

<Window x:Class="Penov.Playground.MainWindow">

The corresponding mainwindow.xaml.cs file contains:

namespace Penov.Playground
{
    public class MainWindow
}

If I want to change the namespace from Penov.Playground, I need to change it in both places. This would result in a .g.cs files generated on the next build with the new namespace.

Franci Penov
  • 74,861
  • 18
  • 132
  • 169
  • 3
    Its answers like this that make SO the wonderful resource I use every day – Spence Dec 30 '11 at 05:03
  • The easiest way is to do a search and replace for the entire project when you change the assembly name. Make sure you use a unique name for template assembly names so that when others do try to search and replace it does not cause residual errors. – VoteCoffee Feb 06 '14 at 13:30