Hi, I have encountered a problem binding to collections that contain an inherited class.
First I have a Class called Employee: See below:
public class Employee |
{ |
public int EmployeeId { get; set; } |
public DateTime DateHired { get; set; } |
} |
Next I have a class that inherits from Employee. See below:
public class AccountingEmployee : Employee |
{ |
public string AccountingFunction { get; set; } |
public int AccountingId { get; set; } |
} |
I then have a Silverlight UserControl, where in the code behind, I create two separate Collections to bind to. Collection of Employee Base Class and Collection of the child AccountingEmployee Class See below:
public List<Employee> EmployeeListToBindToBase { get; set; } |
EmployeeListToBindToBase = new List<Employee>(); |
EmployeeListToBindToBase.Add(new AccountingEmployee {EmployeeId = 123 ... |
EmployeeListToBindToBase.Add(new AccountingEmployee {EmployeeId = 456 ... |
public List<AccountingEmployee> AccountingEmployeeListToBindTo { get; set; } |
List<AccountingEmployee> AccountingEmployeeListToBindTo = new List<AccountingEmployee>(); |
AccountingEmployeeListToBindTo.Add((new AccountingEmployee {EmployeeId = 123 ... |
AccountingEmployeeListToBindTo.Add((new AccountingEmployee {EmployeeId = 456 ... |
In my control, I have a RadViewGrid. For this grid, the ItemSource Binds to: EmployeeListToBindToBase
Also in my control, I also have a ItemSource Source Control whose ItemSource Binds to EmployeeListToBindToBase
<telerikGridView:RadGridView |
AutoGenerateColumns="False" |
ItemsSource="{Binding EmployeeListToBindToBase}" ... |
<ItemsControl |
ItemsSource="{Binding EmployeeListToBindToBase}" ... |
The RadGridView contains columns that binds to all the fields in the Base Class and Inherited Class. See below:
<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding AccountingFunction}"/> |
<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding AccountingId}"/> |
<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding DateHired}"/> |
<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding EmployeeId}"/> |
The item template for the ItemsControl, also has controls, that bind to all the fields in the Base Class and Inherited Class. See Below:
<DataTemplate x:Key="MyAccountingEmployeeTemplate"> |
<StackPanel > |
<TextBlock Text="{Binding AccountingFunction}"></TextBlock> |
<TextBlock Text="{Binding AccountingId}"></TextBlock> |
<TextBlock Text="{Binding DateHired}"></TextBlock> |
<TextBlock Text="{Binding EmployeeId}"></TextBlock> |
</StackPanel> |
</DataTemplate> |
But, when I run the small test app:
for the RadGridView: the values for AccountingFunction and AccountingId (ie. the fields in the inherited class) do not show up. But the Base Class Field Values do show up (ie. DateHired and EmployeeId).
For the ItemsControl: All the values for all four fields show up.
There are no binding errors in the output window in visual studio for missing values in the grid (ie AccountingFunction and AccountingId . I have also placed in ValueConvertors for the RadGridView AccountingFunction and AccountingId Columns, and when I debug through the ValueConvertor code, I can actually see the value being passed in, but ultimately the values for these filelds do not show up in the grid. Therefore, the correct values are being picked up, but they still for some reason, do not show up in the grid.
I am thinking this is a bug, because it DOES work for the ItemsControl, that is binding the same collection.
I also have a separate RadGrdiView grid that is binding to -> public List<AccountingEmployee> AccountingEmployeeListToBindTo { get; set; } , all the values are showing up, but I do need to bind to : public List<Employee> EmployeeListToBindToBase { get; set; }, as this is what the service layer is returning.
I have also attached the small sample app, that reproduces the bug. For some reason, it takes a few minutes for the solution in the zip file (rename the file telerikbinding.jpg to telerikbinding.zip to open in Visual Studio). There is also a attached screenshot (missingvalues.jpg) to illustrate as to what I was talking about above.
Thanks,
Matt