从父 silverlight 页面的文本框到另一个本地 silverlight 用户控件的文本框之间的两种方式绑定

发布于 2024-09-26 03:08:23 字数 563 浏览 1 评论 0原文

我已经使用 DependencyProperty 将值从 silverlight 页面的文本框传递到位于同一页面的外部 silverlight 用户控件,并且工作正常。

但问题是我无法以反向方式绑定页面中的文本框。即当我需要在父页面中更改其用户控件的文本框文本时进行更改。

XAML:

<TextBox x:Name="TextDataCollectionAccounts" Width="200" Height="25" VerticalAlignment="Top"></TextBox>                    
<Local:CalControl   x:Name="RCal" DateRange="{Binding ElementName=TextDataCollectionAccounts, Path=Text, Mode=TwoWay}" Visibility="Collapsed"/>

如何将“TextDataCollectionAccounts”(在 silverlight 页面中)与“Local:CalControl”的文本框绑定?

I have used DependencyProperty to pass value from textbox at silverlight page to external silverlight user control located in same page and that works fine.

But the problem is I could not bind the Textbox in page in reverse way. i.e. when i need to have changes in parent page when its usercontrol's textbox text is changed.

The XAML:

<TextBox x:Name="TextDataCollectionAccounts" Width="200" Height="25" VerticalAlignment="Top"></TextBox>                    
<Local:CalControl   x:Name="RCal" DateRange="{Binding ElementName=TextDataCollectionAccounts, Path=Text, Mode=TwoWay}" Visibility="Collapsed"/>

How to bind "TextDataCollectionAccounts"(in silverlight page) with Textbox of "Local:CalControl"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

单身狗的梦 2024-10-03 03:08:23

基本上永远不要尝试绑定到用户控件的内部工作。将其视为第三方控件并公开属性和事件。

  • 将 TextBox 的 Text 属性公开为用户控件上的 Text 依赖属性。
  • 捕获 TextBox 的更改事件,并为新的 Text 依赖属性引发属性更改事件。
  • 然后,您可以简单地绑定到用户控件上的新 Text 属性。

如果你需要一个具体的例子,尽管问,但听起来你已经快到了并且了解你的 DP。

Basically never try to bind to the inner workings of a user control. Treat it like it was a third-party control and expose properties and events.

  • Expose the Text property of the TextBox as a Text dependency property on your usercontrol.
  • Catch the change event of the TextBox and raise a property change event for the new Text dependency property.
  • Then you can simply bind to your new Text property on your user control.

If you need a specific example, just ask, but it sounds like you are almost there and know your DPs.

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