Silverlight中的DataTemplate内访问元素

编程入门 行业动态 更新时间:2024-10-21 11:26:52
本文介绍了Silverlight中的DataTemplate内访问元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直没能找到一个干净的解决以下问题,即使有几个相关的问题已经在左右。

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内访问元素

本文发布于:2023-11-07 05:32:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565676.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   Silverlight   DataTemplate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!