Silverlight: Why is ItemsSource ignored when set in code for a HierarchicalDataTemplate?
I've defined a HierarchicalDataTemplate in the App ResourceDictionary. If I set the ItemsSource property in XAML, the TreeView looks and behaves as expected. However, if I set the DataTemplate to this object in code, remove the 开发者_开发问答ItemsSource value from XAML and instead set it in code (like the following example), it gets ignored and the tree nodes don't show any children. Why is this and how can I get around it?
var node = item as Node;
var template = App.Current.Resources["NodePresenterTemplate"] as HierarchicalDataTemplate;
template.ItemsSource = node.ChildNodes; // ignored in Silverlight, works in WPF
return template;
精彩评论