简体   繁体   中英

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. 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. Is there any way to just let the TextBox properties to be accesible fron XAML?

Yes, you can do it. Give your TextBox in UserControl name:

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

In code behind of your UserControl define a property:

public TextBox UscTexBox { get { return uscTbx; }}

In XAML of another windows you can acces the properties of your TextBox:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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