tags:

views:

79

answers:

1

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"))?

A: 

You could 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 /> 

Regards,

H.Dolder [www.hdolder.com]

H.Dolder
I appreciate the response, but I specifically want to avoid this (see above).
Chris Simmons
To avoid repeating this (in many of your XAML Files):xmlns:foo2="clr-namespace:NS2;assembly=AssemblyName" I proposed this (in the Assembly):[assembly: XmlnsDefinitionAttribute("urn:foo2", "NS2")] Regards,H.Dolder
H.Dolder