简体   繁体   English

绑定用户控件

[英]binding usercontrol

How can I create a binding to a property defined in an UserControl from XAML which includes it? 如何创建对包含XAML的UserControl中定义的属性的绑定? For example, I have a control of type local:Photo named thePhoto, which has three controls local:Layer called Main, Frame and Text, and I want to access thePhoto.Main.ActualWidth from my MainWindow? 例如,我有一个名为thePhoto的local:Photo类型的控件,它具有三个名为local,Layer的控件,分别名为Main,Frame和Text,我想从MainWindow访问thePhoto.Main.ActualWidth吗? Thanks 谢谢

(I forgot to say that simple Binding with Path and ElementName doesn't work) (我忘了说用Path和ElementName进行简单的绑定是行不通的)

Create DependencyProperty of desired type within "parent" UserControl and bind it with needed Properties on both sides. 在“父” UserControl创建所需类型的DependencyProperty ,并将其与两侧所需的Properties绑定。
Nice example of doing stuff like that: Exploring the use of Dependency Properties in User Controls 做这样的事情的好例子: 探索用户控件中依赖项属性的使用

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

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