Ag UserControl 是否可以公开供 XAML 绑定的属性?
我有一个由 UserControl01.cs
支持的新 UserControl,它公开了两个属性。 一种是普通的旧 CLR 属性,另一种是较新的 DP 属性格式。 例如:
string PropertyOne {get;set;}
第二个属性是公共 DP(构造太长,无法在此处列出)。
从 XAML 方面,我希望公开这些值。 我怎样才能做到这一点?
在这两个属性(旧的 CLR 以及第二个 DP 包装器格式)上,我尝试过如下语法:
<TextBlock Text={Binding Prop1}/>
<TextBlock Text={Binding Source=., Path=Prop1}/>
我尝试在资源字典中放置对类类型的引用并引用它,
<TextBlock Text={Binding Source={StaticReference myType}, Path=Prop1}/>
但这显然最终会导致堆栈溢出,如下所示该字典实例化该控件的第二个副本。
我在某处读到一篇文章,在 WPF 中可以 x:Name
控件本身,但是
<TextBlock Text="{Binding {ElementName=theName, Path=Prop1}"/>
我们在 Ag 中没有 ElementName 绑定,所以这不是方法。
- 如何绑定到 UserControl 的属性? 任何财产!
- 如果这是不可能的,并且您只能绑定到 DTO 或其他 BO,那么我们应该如何设计想要公开其值的 UserControls 的指导逻辑/解释是什么?
I have a new UserControl backed by UserControl01.cs
that is exposing two properties. One is a plain old CLR property, the other the newer DP property format.
eg:
string PropertyOne {get;set;}
and the second property is a public DP (construct is too long to list here).
From the XAML side, I wish to expose these value. How can I do that?
On both properties (old CLR as well as second DP wrapper format) I've tried syntax like:
<TextBlock Text={Binding Prop1}/>
<TextBlock Text={Binding Source=., Path=Prop1}/>
I've tried putting a ref to the class type in the Resource dictionary and referencing it with
<TextBlock Text={Binding Source={StaticReference myType}, Path=Prop1}/>
but that obviously ends up being a stack overflow as the dictionary instantiates a second copy of the Control.
I read a post somewhere that in WPF one can x:Name
the control itself, and then
<TextBlock Text="{Binding {ElementName=theName, Path=Prop1}"/>
but we don't have ElementName binding in Ag, so that's not the way.
- How can I bind to the UserControl's property? Any property!
- If that's not possible, and you can only bind to DTO's or other BO's, what's the guiding logic/explanation as to how we should design UserControls that want to expose their values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Silverlight 3有控件来控制绑定。
http://silverlight.net/learn/learnvideo.aspx?video=187309
Silverlight 3 has control to control binding.
http://silverlight.net/learn/learnvideo.aspx?video=187309