This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I am trying to create a MultiColumnTreeView to represent the following data: A family object which has two properties, Name and the number of members belonging to the family (Count) as well as collection of Members of the family which has the following three properties (Name, DOB, Gender). I am trying to render the information as follows, Jane Robinson 01/01/08 F John Robinson 01/01/08 M |
|
|
The way around this is to use CellTemplateSelector instead of CellTemplate or DisplayMemberBinding. In your CellTemplateSelector, examine the type of the item and hand off to a suitable DataTemplate or an empty template appropriately. Here's an example from a sample we're working on at the moment. In this example, we have a hierarchy of Countries, Companies and People, and our columns are Name, Contact Info and Notes. Unfortunately for us, the Person class doesn't have a Name property, only FirstName and LastName properties; Companies have a set of address properties for their contact info, People have an EmailAddress property and Countries don't have contact info at all; and finally Countries don't have Notes. The first thing we do is create a generic selector that just looks at the type of the item: public class EntityTypeTemplateSelector : DataTemplateSelector As the comment indicates, I've ducked making this fully generic: it's tied specifically to my hierarchy. This could be fixed by having a set of type-template pairs instead of the specific templates, but this makes the selector declarations in XAML a bit more verbose. Let me know if you want to see that approach anyway. Now we can start creating and selecting templates in our XAML. I'll show the Name and Notes because that should be enough to give you the idea. <DataTemplate x:Key="EmptyTemplate"> <ms:MulticolumnTreeView.Columns> This should address both your databinding errors (via the use of EmptyTemplate) and showing the number of members in the family (have your FamilyNameTemplate have text blocks bound to Name and Count, as we do above for Person FirstName and LastName). Hope this makes sense -- let me know if you need any more info on this. |
|