[英]TextBox with ControlTemplate - problem with property Text
I have one big problem with passing value from a ControlTemplate
to the control. 将值从ControlTemplate
传递到ControlTemplate
,我遇到了一个大问题。 TextBox
has a ControlTemplate
, how can I pass value from this template to the TextBox
text? TextBox
有一个ControlTemplate
,如何将值从此模板传递给TextBox
文本?
All you need is a container with the name PART_ContentHost
. 您只需要一个名称为PART_ContentHost
的容器。
Here's the complete example on how to create a control template for a textbox: TextBox Styles and Templates . 这是有关如何为文本框创建控件模板的完整示例: TextBox样式和模板 。 In this case the textbox is presented inside a ScrollViewer
. 在这种情况下,文本框显示在ScrollViewer
。
Hope it helps! 希望能帮助到你!
If I truly understand your problem, you want to Show Text Value of Textbox in custom Textbox Control. 如果我真正了解您的问题,则希望在自定义“文本框控件”中显示“文本框的文本值”。 So for doing this, you must use Template-Binding
in template Like : 因此,为此,您必须在模板Like中使用Template-Binding
:
<CustomControl Text="{TemplateBinding Text}">
CustomControl refer to any control you use in Template. CustomControl引用您在Template中使用的任何控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.