views:

95

answers:

2

Hello!

Here are the DataTemplates:

<DataTemplate DataType="{x:Type data:Item}" x:Key="ItemTemplate">
    <Border/>
</DataTemplate>

<DataTemplate DataType="{x:Type data:StyleItem}" x:Key="StyleItemTemplate">
    <Border>
        <ContentControl Content="{Binding Item}" 
                ContentTemplate="{StaticResource ItemTemplate}"/>
    </Border>
</DataTemplate>

I am trying to bind a List<StyleItem> to an ItemsControl,
setting ItemTemplate="{StaticResource StyleItemTemplate}", but then I get a System.Reflection.AmbiguousMatchException.

I read this post, and althoug the StyleItem and Item classes are not generic classes, anyhow; I don't know how to use the parenthsis solution in my situation.

The Item and StyleItem classes are generated EF entities that inherit from System.Data.Objects.DataClasses.EntityObject, and implement System.ComponentModel.IDataErrorInfo.

A: 

You should either use the x:Key property or the DataType property.

You must not use both. So remove either one to get it to work! I suggest removing the DataType property, since you already use the keys in your example!

Arcturus
Well I removed the DataType property and still doesn't work.About removing the key, how do I refer to it if it doesn't have key? Did you test this and it works for you!? cuz for me it doesn't :'(
Shimmy
You do not need to refer to DataType. When you have a list or a ContentControl (like Button), WPF will check if there are any DataTemplates defined for the current DataContext and use that one.
Arcturus
+2  A: 

This smells like a collision between your StyleItem.Item property and the property indexer defined in IDataErrorInfo. Try changing the name of your StyleItem.Item property to something else.

Aviad P.
You were efin right!!! you're good man, I was struggling a lot with this issue!אתה המלך!
Shimmy
Who would have thought :) בבקשה!
Aviad P.