About Micsoft.Xaml.Behaviors ambiguous reference problem #147
-
I have found that when I installed the Microsoft.Xaml.Behaviors.Wpf package or other packages which are dependent on the Microsoft.Xaml.Behaviors.Wpf package and also installed iNKORE.UI.WPF at the same time, the compiler throws an AmbiguousReference error. This problem bothers me and hoping for some advices. Thanks so much. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
For some reason, we have to copy the source of Microsoft.Xaml.Behaviors.Wpf into the iNKORE.UI.WPF library. And these two are totally the same, which means you don't need to install the Microsoft.Xaml.Behaviors.Wpf package again. If you need Microsoft.Xaml.Behaviors.Wpf, try this: using InvokeCommandAction = Microsoft.Xaml.Behaviors.InvokeCommandAction; |
Beta Was this translation helpful? Give feedback.
-
@SerenniaHan Well things get a little bit different when things come to XAML. As you know the namespace of C# code is defined directly in the .cs file. However, the xaml namespaces are defined in the AssemblyInfo: [assembly: XmlnsPrefix(@"http://schemas.microsoft.com/xaml/behaviors", "b")]
[assembly: XmlnsDefinition(@"http://schemas.microsoft.com/xaml/behaviors", "Microsoft.Xaml.Behaviors")]
[assembly: XmlnsDefinition(@"http://schemas.microsoft.com/xaml/behaviors", "Microsoft.Xaml.Behaviors.Core")]
[assembly: XmlnsDefinition(@"http://schemas.microsoft.com/xaml/behaviors", "Microsoft.Xaml.Behaviors.Input")]
[assembly: XmlnsDefinition(@"http://schemas.microsoft.com/xaml/behaviors", "Microsoft.Xaml.Behaviors.Layout")]
[assembly: XmlnsDefinition(@"http://schemas.microsoft.com/xaml/behaviors", "Microsoft.Xaml.Behaviors.Media")] Because both of the two libraries are defining the same 'http://schemas.microsoft.com/xaml/behaviors' for their own version of code base, for the IDE, he has no idea which one to use. There's actually a workaround, which is to change the xmlns to clr-namespace. Since a clr-namespace clearly specifies which assembly to use, this can be solved. For example your code might look like this before: xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
<Border b:Interaction.Behaviors="{x:Null}"/> Now change to the clr-namespace, which looks like this: xmlns:b="clr-namespace:Microsoft.Xaml.Behaviors;assembly=iNKORE.UI.WPF" // or any other source you like In this way, the compiler would clearly know which assembly you want him to use, and ambiguous reference would gone. Now I'm starting to wonder that embedding Microsoft.Xaml.Behaviors.Wpf into the iNKORE.UI.WPF library is a pretty bad idea, which causes the conficts and also duplicates the bundled code. However, many users have reported that they do not want to see addtional dll files in their output directory. It's like, uhh, I'm using iNKORE.UI.WPF series, why would I have to incude a Microsoft.Xaml.Behaviors.Wpf into my output? Well that's why we finally decided to do the embedding thing. They have also considered using a shell or something like fody, but these are not the choice of most people. |
Beta Was this translation helpful? Give feedback.
@SerenniaHan Well things get a little bit different when things come to XAML. As you know the namespace of C# code is defined directly in the .cs file. However, the xaml namespaces are defined in the AssemblyInfo: