开发者

Silverlight: Why is ItemsSource ignored when set in code for a HierarchicalDataTemplate?

开发者 https://www.devze.com 2022-12-11 05:25 出处:网络
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

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消