且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#在Silverlight 4.0中动态地将ItemTemplate添加到Treeview

更新时间:2023-01-26 14:06:38



您应该将Template-resource(直接或通过合并的ResourceDictionary)移动到Application.Resources中.然后您可以通过
实例化它
Hi,

you should move the Template-resource into the Application.Resources (either directly or via a merged ResourceDictionary). Then you can instantiate it by
DataTemplate mytemplate = Application.Current.Resources["EmailItemTemplate"] as DataTemplate;
mt[0].ItemTemplate = mytemplate;


我不确定这是否可以与资源"Name"属性一起使用;通过"Key"属性,它将并且我仅将其与样式资源一起使用,但我认为其他资源也可以使用.

干杯.


I''m not quite sure if that works with the resources "Name" property; with the "Key" property it will and I''ve only used this with Style-resources but I think other resources will work as well.

Cheers.