Use the XAML namespace refactoring tools to add XML namespace, change prefix names, and rename prefixes.
- [Instructor] I'm looking at the XAML editor for this main page inside this Universal Windows application project, and I'm going to look at some of the refactoring tools that have been added to the XAML editor, specifically for the refactoring tools available for XML namespaces. Now, let's review the situation before 2017. I've got this custom user control here, Alarm Clock, and it is in a namespace called Refactor.Clocks.AlarmClock, whereas my main page is in a separate namespace, it's in Refactor, so I would need to add an XML namespace to my document in order to bring that user control into scope, so I would come in here, type in my prefix, choose from my available namespaces, and then, once I've got the namespace set up, I can use it in my XAML, like that.
In the new version of Visual Studio, we have this refactoring tool that can help in some of these situations. Let me delete the code I just added. And then I'll go back to the stack panel and see that the alarm clock is not showing up. This is because the namespace is not in scope yet. I'm going to keep typing it. Now, once I finish typing this, Visual Studio analyzes this line of code, looks through all of the namespaces available to my code, and sees that there is a type that matches this, I just didn't have the correct namespace declared at the top of my document, so I'll get this quick action.
It's suggesting that I add XML namespace with the correct using statement there. I like this, so I'll double-click, and two things happened. It added a prefix to my element, and it also added, on line seven, the correct XML namespace. I'll add another element to my stack panel, I've got two of these user controls, and now, I'll show you the other refactor, which is the rename refactor. Maybe I'm not happy with this XML namespace. Maybe I've copied this code from another part of my UI, and dropped it in here, and I'm not happy with the namespace yet, so I want to modify it.
Select one of the alarm clocks and go to Edit and Refactor, choose Rename. You get the standard renaming UI that you see in other parts of Visual Studio, and now, I can just type in the new name, and now, I got a couple choices, here. I can just press the Enter key, or I can clock on the Apply button.
- Installing Visual Studio 2017
- Using debugging features
- Reviewing document navigation enhancements
- Examining IntelliSense Improvements
- Using XAML tools
- Reviewing the tooling added to support Docker containers
- Debugging without the hosting process
- Using the Visual Studio 2017 Installer