我一直没能找到一个干净的解决以下问题,即使有几个相关的问题已经在左右。
I have not been able to find a clean solution to the following problem even though there are a few related questions already on SO.
如果我有一个数据模板正在使用多次,例如TreeViewItem.HeaderTemplate,我怎么能换东西的模板,只有一些TreeViewItems的。
If I have a data template that is being used multiple times, for example, a TreeViewItem.HeaderTemplate, how can I change something the template for only some of the TreeViewItems.
例如,假设我。TVI HeaderTemplate中有一个文本块,并根据不同的字符串,我想使粗细粗体
For example, let's say my TVI HeaderTemplate has a textblock and depending on the string, I want to make the fontweight bold.
我想要做这样的事情:
((TextBlock)myTreeView.Items.ElementAt(0).FindName("myTextBlock")).FontWeight = FontWeights.Bold;
有没有人有一个解决方案? - >感谢埃文
Does anyone have a solution for this? --> Thanks Evan
编辑:有没有写一个通用功能的基础上,即使它在它的名字得到控制的一种方式数据模板
Is there a way to write a generic function to get a control based on it's name even if it's in a data template?
LayoutRoot.FindName(myTextBlock); 如果myTextBlock在一个DataTemplate是不是会工作。我怎么能写一个 findElementInDataTemplate(字符串的ElementName,串parentName)功能?
LayoutRoot.FindName("myTextBlock"); would work if myTextBlock was not in a datatemplate. How can I write a findElementInDataTemplate(string elementName, string parentName) function?
原因埃文的回答是不是我要找的是因为我开发的控件。我想谁使用我的控制,能够改变任何元素控制应用程序开发人员。如果我使用埃文的解决方案,这需要应用程序开发人员能够访问控件中的所有模板。有可能,但不理想。谢谢!
The reason Evan's answer is not what I'm looking for is because I am developing a control. I want the application developer who uses my control to be able to change any element in the control. If I use Evan's solution, that would require the application developer to have access to all the templates in the control. Possible, but not ideal. Thanks!
推荐答案什么版本的Silverlight是这样吗? 和在18:55 08月10日哪一年是来自哪里?
what version of silverlight is this? And what year of " Aug 10 at 18:55" is this post from?
在SL4的当前版本中它似乎并不在那里这个职位。
in the current version of SL4 it does not seem to be there..
更多推荐
Silverlight中的DataTemplate内访问元素
发布评论