Best way to rename MainWindow

Go To StackoverFlow.com

5

In Visual Studio 2010, if I create a new project that is a WPF Application, the MainWindow subclass of Window is provided as a default first window. The steps I've been taking to rename MainWindow are:

  • Use Solution Explorer to rename MainWindow.xaml.
  • Rename the class in MainWindow.xaml.cs.
  • Select the "Rename 'MainWindow' to ..." option from the "Options to update references to the renamed object" popup menu which appears next to the renamed class.
  • Update StartupUri in App.xaml accordingly.

Is there a better way? :-)

2012-04-04 01:22
by dharmatech


6

  1. Get ReSharper
  2. Use Rename
  3. ????
  4. Profit
2012-04-04 01:37
by Anurag Ranjhan
+1 You stole my answer - Ritch Melton 2012-04-04 01:38
Perhaps you mean ReSharper? :- - dharmatech 2012-04-04 18:39
Thanks for the pointer to ReSharper Anurag. Didn't know about it. Unfortunately, I'm using Visual C# 2010 Express, which doesn't appear to be supported by ReSharper - dharmatech 2012-04-04 18:40
@dharmatech Edited :). Yes Express does not support addin. If you really want it to be easier you can try SharpDevelop... I have no experience with it, but have read good things - Anurag Ranjhan 2012-04-04 18:54


2

Visual C# 2010 Express Has a built in option to solve this.You can see the menu bar has an option "Refactor" where you can see two sub-menu Rename and Refactor.To change any name you just have to take the cursor on the name(Calculater in image) and click right button.Then go to Refactor and click Rename.You will see a dialog box comes and then you put the new name you want to give to your attribute.

enter image description here

2012-04-19 19:14
by Ashad Shanto
Hello @MohammadAsad. Yes, that feature will rename the method. However, it appears that, in the case of MainWindow, you'll still have to up date StartupUri manually. But it's good that you mention this feature, for completeness - dharmatech 2012-04-19 21:36
This actually works well as long as you do things in the right order. 1. Refactor/Rename class 2. Rename the file in Solution Explorer 3. Replace the StartupUri in App.xaml with new nam - jsmith 2015-11-19 14:48


1

I cannot think of a better way. An alternative which may result in less steps could be to create a new window and then set the StartupUri to the name of your new window.

It is then up to you whether you want to keep MainWindow or delete it (which would make sense if you are not using it at all).

2012-04-04 01:36
by onefootswill
Ads