My problem is distinct from this other question Enforce Global Namespace in XAML in that I don't have a class with the same name as the enclosing namespace, yet I couldn't think of a more appropriate title that would differentiate the two.
If any part of my XAML object's namespace is also the root of another namespace, Visual Studio seems to prefer my XAML object's namespace, which manifests as a compiler error.
Here is an example that shows how part of my namespace WpfApp1.System.Views
clashes with global::System
:
<Window x:Class="WpfApp1.System.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<!-- Amazing content goes here -->
</Grid>
</Window>
There are compilation errors shown in the Errors pane and obj/System/Views/MainWindow.g.i.cs
shows this with a squiggly red underline under the System
part of System.Windows.Window
:
namespace WpfApp1.System.Views {
public partial class MainWindow : System.Windows.Window {
// ...
}
}
Obviously my toy example only stops me from having a System
namespace anywhere in my hierarchy, but it also stops me from having any 3rd-party names (like DevExpress
) if I'm using one of those 3rd-party components in XAML.
Without renaming either my own namespace (or the referenced components' namespaces) can I ask Visual Studio to use global::
namespaces in its generated XAML code?