Monday, April 14, 2008

Renaming Xaml Files

Okay, the record now is 343 days between posts. Still holding at under a year between posts, but rising. If somebody would please post a comment to encourage more posts,... that wouldn't help, because I only log in to make new posts. Hmmm....

I got a free copy of Visual Studio 2008, Standard Edition, from Microsoft for attending the launch ceremony in San Francisco on March 13. I am sad that they did not give me the Professional Edition, as they did in 2005. But free is free, right?

Now I am using said product, and I have found a bloggable issue here.

The issue is renaming the xaml file in a WPF application. I actually sent in a comment during the Beta period, and Microsoft replied that they were aware of the issue, but had decided not to fix it at this time. (We Ignore You, Puny Customer.)

So, anyway, you make a new WPF project in VS08, and the template kindly provides you with a Window1.xaml and a Window1.xaml.cs code-behind file. Of course, you want to rename that to a more meaningful name. Maybe you want it called DVDList.xaml and DVDList.xaml.cs. So what do you do, kids in the peanut gallery? You right-click the file in the Solution Explorer and select Rename from the context menu. This allows you to type a new name for the xaml file, and miraculously also renames the .cs file. Whoopee, so far so good.

Great! Press F6 and it all compiles without error or warning. Press F5 to run, and you get an IO Exception saying that Window1 is not found!

Huh? But didn't you just rename that? Ho, ho, no. This is not like the good-old Windows Forms application you're used to, where it runs a refactor, rename feature. No, no. This is the new, improved, WPF environment.

Improved, except that they've taken away the rename functionality!

What's the word for that? Disimproved? Unimproved. Worsened? Whatever it is, you had it before and they took it away!

So. What you have to do is a global rename. Typically, you hit ctrl+shift+H to get the replace-in-files dialog. Then change every instance of Window1 to DVDList in all files in the current project.

And for God's sake, don't let the FX cops find out you named it DVDList. They'll be all over your ass for that.

Labels:

0 Comments:

Post a Comment

<< Home