Silverlight Treeview DisplayMemberPath not working
I have a ObservableCollection of Patient objects. Each Patient object has a Name property, an Id (int) and a List of Therapies. Each Therapy has a TherapyName(string). I'm using the TreeView to display the data like this
<sdk:TreeView ItemsSource="{Binding PatientList}" DisplayMemberPath="Name" >
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Therapies}" >
<TextBlock Text="{Binding TherapyName}"/>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
When I run it, it crashes inside the browser.When i remove the DisplayMember开发者_C百科Path, it runs but I only get the TherapyNames, the parent elements for Patient Names are empty.
you shouldnt have display member path there as this is used if you are using item source and the in that obejct wanting to select values are used for the tree.
you want to do some thing like this
<sdk:TreeView ItemsSource="{Binding PatientList}" DisplayMemberPath="Name" >
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Therapies}" >
<Stackpanel>
<TextBlock Text="{Binding TherapyName}"/>
<TextBlock Text="{Binding Name}"/>
</Stackpanel>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
I havnt tested that bit of xaml but it should be nearly right
精彩评论