【发布时间】:2013-05-03 06:01:59
【问题描述】:
我在 ResourceDictionary Generic.xaml 中覆盖了控件的模板。在那我添加了一个按钮,我想在上面添加一些事件。
<Setter Property="Template">
<Setter.Value>
--Added my button here.
</Setter.Value>
</Setter>
所以在加载控制事件中我做了
Button b = (Button)mycontrol.Template.FindName("PARTName", mycontrol)
//Add Events on my button
我在互联网上读到的一些我可以做到的地方
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
UIElement editingelement = GetTemplateChild("PART_EditingElement");
if (editingelement != null)
{
// do something
}
}
当我尝试为 GetTemplateChild 执行此建议时,说不要使用。
所以我的问题是
为什么不使用
GetTemplateChild。它已经过时了吗?还有FrameWorkTemplate.FindName和ControlTemplate.FindName有什么区别?
【问题讨论】:
-
回答您的 2. 问题。
ControlTemplate继承了FrameworkTemplate,所以差别不大。看here
标签: c# wpf controltemplate