Ag UserControl 是否可以公开供 XAML 绑定的属性?

发布于 2024-07-15 05:35:27 字数 936 浏览 3 评论 0原文

我有一个由 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 绑定,所以这不是方法。

  1. 如何绑定到 UserControl 的属性? 任何财产!
  2. 如果这是不可能的,并且您只能绑定到 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.

  1. How can I bind to the UserControl's property? Any property!
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2024-07-22 05:35:27

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文