简体   繁体   English

从UserControl的属性访问内部控件的所有属性

[英]Access from UserControl's properties to all of a inside control's properties

So, i made a "custom textbox". 因此,我做了一个“自定义文本框”。 The UserControl is just a Grid with a Rectangle and a TextBox, some code behind just colores the rectangle if the mouse is over and colores the text of the TextBox is it's keyboard focussed. UserControl只是一个带有矩形和TextBox的网格,后面的一些代码只是在鼠标悬停时为矩形着色,并为键盘聚焦的TextBox文本着色。 I want to have acces to all the properties a TextBox has without having to manualy wire every one up by setting dependency properties and then binding them up in XAML. 我希望访问TextBox的所有属性,而不必通过设置依赖项属性然后在XAML中将它们绑定起来来手动连接每个属性。 Is there any way to just let the TextBox properties to be accesible fron XAML? 有什么方法可以让TextBox属性在XAML中使用吗?

Yes, you can do it. 是的,您可以做到。 Give your TextBox in UserControl name: UserControl给您的TextBox名称:

<TextBox x:Name="uscTbx" Text={Binding toSomething}/>

In code behind of your UserControl define a property: UserControl后面的代码中定义一个属性:

public TextBox UscTexBox { get { return uscTbx; }}

In XAML of another windows you can acces the properties of your TextBox: 在另一个窗口的XAML中,您可以访问TextBox的属性:

<local:UserControl1 x:Name="usc1"/>
<TextBox Text="{Binding Path=UscTexBox.Text, ElementName=usc1}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM