Weird behaviour when binding to (the programmatic construct) interface
Well, a couple of days ago a coworker and I came across a very strange behaviour concerning Expression Blend while binding to a generic list of an interface. And we were able to reproduce the same behaviour in Visual Studion 2008 as well.
In our example ObservableCollection![]()
Anyway, so IMitarbeiter is the interface describing an employee and here is the important part: it is derived from another interface IPerson (where you are in luck, because German Person = English person. Great stuff, hugh?)
So basically the interface is:
- public interface IMitarbeiter : IPerson
- {
- string Email { get; }
- IArbeitsplatz Arbeitsplatz { get; }
- }
EMail = email (dugh) Arbeitsplatz = working space
And here is the definition for IPerson:
- public interface IPerson
- {
- IPersonName Name { get; }
- byte[] Bild { get; }
- string Beschreibung { get; }
- }
Name = name (double dugh) Bild = picture Beschreibung = description
So. As I said the interface IMitarbeiter is now used to define a generic list ObservableCollection
), we are stricktly concerned with interface matters.
All that is done by the developer is create this codebehind:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Collections.ObjectModel;
- using System.Drawing;
- public partial class MainForm : Window
- {
- public ObservableCollection<IMitarbeiter> MitarbeiterCollection
- {
- get { return m_MitarbeiterCollection; }
- }
- ...
- }
So we are firing up Expression Blend and start doing the object binding, go to the "Create Data Template" Dialog and see this:
So we ONLY see the stuff defined in IMitarbeiter. No Fields coming from IPerson! Why that is is absolutely not clear. Most likely the deverloper of the code that does the reflection to analyse the interface did pass the wrong value that controlled the walking of the inheritance tree. The fun part is: This behaviour is totally reproducable in ASP.NET's databinding as well.
I have to emphasis, this is absolutely a GUI bug. When handcoding against the interface's properties everything works as expected.
I am sorry about this hurried post - but actually we started boarding and I am the last person sitting out her - and the nice lady behind the counter is starting to give me some nasty looks. Gotta go.

Actually this behaviour is related to this:
http://saftsack.fs.uni-bayreuth.de/~dun3/archives/weird-surprise-while-using-flattenhierarchy-on-interfaces/160.html
Most likely the developer of this feature did stumble accross the same problem…
Comment on July 15, 2008 @ 10:58:05