Let's assume I have the following attributes on my assembly:
[assembly: XmlnsDefinitionAttribute("urn:foo", "NS1")]
[assembly: XmlnsDefinitionAttribute("urn:foo", "NS2")]
Then let's assume I have a few classes in that assembly:
namespace NS1
{
public class Class1 {}
}
namespace NS1
{
public class Class2 {}
}
namespace NS2
{
// Here's the duplicate class name. OK in C#, but ambiguous in XAML
public class Class1 {}
}
Then let's assume that my XAML is like so:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:foo="urn:foo"
Title="MainWindow" Height="350" Width="525">
<ListBox>
<foo:Class2 />
<foo:Class1 /> <!-- XAML parser does not like this: Ambiguous type reference -->
</ListBox>
</Window>
Putting aside any design issues with having two or more classes named the same within an assembly, is there any way to provide the needed specificity without resorting to this?
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:foo="urn:foo"
xmlns:foo2="clr-namespace:NS2;assembly=AssemblyName"
Title="MainWindow" Height="350" Width="525">
<ListBox>
<foo:Class2 />
<foo2:Class1 />
</ListBox>
</Window>
In some special XAML syntax? In an attribute I can put on NS2.Class1
(e.g. XamlClassName("NS2_Class1")
)?