XmlnsDefinitionAttribute and ambiguous types

Suppose I have the following attributes on my assembly:

[assembly: XmlnsDefinitionAttribute("urn:foo", "NS1")] [assembly: XmlnsDefinitionAttribute("urn:foo", "NS2")] 

Then let's say that I have several classes in this assembly:

 namespace NS1 { public class Class1 {} } namespace NS1 { public class Class2 {} } namespace NS2 { // Here the duplicate class name. OK in C#, but ambiguous in XAML public class Class1 {} } 

Then suppose my XAML looks like 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" Title="MainWindow" Height="350" Width="525"> <ListBox> <foo:Class2 /> <foo:Class1 /> <!-- XAML parser does not like this: Ambiguous type reference --> </ListBox> </Window> 

Discarding any design problems with the presence of two or more classes called the same in the assembly, is there a way to provide the necessary 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 the attribute, can I put on NS2.Class1 (for example, XamlClassName("NS2_Class1") )?

+4
source share
1 answer

You can use:

 [assembly: XmlnsDefinitionAttribute("urn:foo", "NS1")] [assembly: XmlnsDefinitionAttribute("urn:foo", "NS2")] [assembly: XmlnsDefinitionAttribute("urn:foo2", "NS2")] 

and then:

 xmlns:foo2="urn:foo2" 

and finally:

 <foo2:Class1 /> 

Hi,

H. Dolder

+1
source

All Articles