开发者

XmlnsDefinitionAttribute and ambiguous types

开发者 https://www.devze.com 2023-01-08 18:50 出处:网络
Let\'s assume I have the following attributes on my assembly: [assembly: XmlnsDefinitionAttribute(\"urn:foo\", \"NS1\")]

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
{
    pu开发者_开发问答blic 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"))?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消