[英]Are nested Templated Controls permitted
I have a Templated Control that works correctly in XAML documents. 我有一个在XAML文档中可以正常工作的模板控件。 However, when I include it in the XAML body of another Template, it doesn't work correctly.
但是,当我将其包含在另一个模板的XAML主体中时,它无法正常工作。 It displays, but its
OnApplyTemplate()
method is never called. 它显示,但从未调用其
OnApplyTemplate()
方法。
Can I use "nested" Templated Controls? 我可以使用“嵌套”模板控件吗?
I created a simple example of nested Templated Controls which worked without problem. 我创建了一个简单的嵌套模板化控件示例,该示例可以正常工作。 So the simple answer is yes, nested Templated Controls work correctly.
因此,简单的答案是肯定的,嵌套模板控件正确运行。 I still haven't determined why my real code isn't working, but I'm sure it's user error.
我仍然不确定为什么我的真实代码无法正常工作,但是我确定这是用户错误。 While UserControl's are easier, at least for me, both these Templated Controls included
<ContentPresenter>
markup, and I don't know how to do that in a UserControl. 尽管UserControl更容易,但至少对我来说,这两个模板控件都包含
<ContentPresenter>
标记,而我不知道如何在UserControl中做到这一点。
But that's another question. 但这是另一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.