XamComboEditor.CheckDisplayMemberPath mishandles the situation where DisplayMemberPath is declared in a base interface. That is, given:
public interface IBase { string DisplayName { get; } }
public interface IDerived : IBase { }
public class Derived : IDerived { public string DisplayName { get { return "DisplayName"; } }
<ig:XamComboEditor ItemsSource="{Binding Items}" DisplayMemberPath="DisplayName"/>
If the ItemsSource is ObservableCollection<Derived>, everything works, but if ItemsSource is ObservableCollection<IDerived> CheckDisplayMemberPath throws, which I believe is a bug.
See the attached zip for a repro
Cheers
James
Hello James,
Thank you for your feedback. I believe that other community members may benefit from this as well.
Thanks again.
Somewhere in CheckDisplayMemberPath, you do something like
type.GetProperty(DisplayMemberPath)
which will return a PropertyInfo if there's a property with the name in DisplayMemberPath in 'type' - but it doesn't look at base classes
If you change that to
type.GetProperty(DisplayMemberPath, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy)
It'll look for properties with the same name on 'type' but include all of the base types in the search (Instance|Static|Public are the default flags for the call without BindingFlags). I believe the subsequent binding code will just work (the concrete object being bound to does implement the property after all)
I'm not sure that the stock combobox does the same check at all - if you don't have a displaymemberpath, it just does .ToString(), and if you do, but it doesn't exist, you get a binding warning and an empty string in the list.
Hope that helps
Hello,
I have been looking into your requirement, but I am not completely sure that this could be done. If you have some example with the Microsofts’s ComboBox I will be glad to investigate it and try to implement it in our XamComboEditor.
Looking forward for your reply.
Yeah, adding the property to IDerived is exactly what I did all those months ago, but it makes the base interface pretty pointless if I have to redeclare common properties in each derived interface.
My point was the check function (which presumably is already reflecting to find the property) should not just look at the top level interface, but base interfaces too.
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into your post sample project you have provided and I modified it, so now it works as expected.. basically I add the Property of your Derived class to the IDerived interface, because when you have an object of type IDerived the XamWebComboEditor cannot bind correctly if there is no Property.
Feel free to write me if you have further questions.