I have a scene in my WPF project with about 2000 different user controls:
<local:MyControlType x:name="aaka4sn9f" />
<local:MyControlType x:name="aaks22nf_1" />
<local:MyControlType x:name="aa66s2f_2" />
and so on down the screen…
Is there a way to rename all of these controls using Visual Studio (and possibly a regex) to be:
<local:MyControlType x:name="myControl1" />
<local:MyControlType x:name="myControl2" />
<local:MyControlType x:name="myControl3" />
??
Thanks a lot!
Visual Studio has Regex capability in its search (and replace). Press
Ctrl+H, expand "Find Options" and click the bottom-most checkbox, "Use." Make sure "regular expressions" is selected.I don’t think you’ll be able to get the increments going using this technique, but you can name all the controls the same thing, like "myControlx", then use a regex to search (not replace) for, say
x". You can then quickly move to each location usingF3and enter the numbers.If you have any experience with more "featureful" text editors, like Vim, open the xaml file in that and make the changes.
Edit:
Using Vim this can be done in two commands (but you’ll need to install the increment.vim plugin from here: http://www.vim.org/scripts/script.php?script_id=842).
:%s/x:name="\zs.\{-}\ze"/myControl@/g(replaces x:name attributes withmyControl@):%Inc(replaces all@with an incremented integer)