我们可以更新不符合 DepencyProperty 或不符合 INotifyPropertyChanged 的源吗
我有一个来自应用程序核心的业务对象。该对象不继承自 INotifyPropertyChanged。它包含我的 XAML 代码绑定到它的一些属性。 我只想动态更新属性而不是 UI(OneWayToSource 样式)。
例如,如果我更改文本框的文本,源项目不会更新。 silverlight的一个限制是,如果对象没有实现INotifyPropertyChanged或使用DepencyProperties,则绑定的源无法更新?
I have a business object that comes from the core of the application. That object does not inherit from INotifyPropertyChanged. It contains some property that my XAML code bind to it.
I only want to update the properties not the UI dynamically (OneWayToSource style).
By example, if I change the text of a text box, the source item does not get updated.
It is a limitation of silverlight that if the object does not implement INotifyPropertyChanged or use DepencyProperties that the source of the binding cannot be updated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
源属性不需要是依赖属性,公开它的类也不需要实现 INotifyPropertyChanged。
如果您将
TextBox
上的绑定设置为使用TwoWay
模式,则编辑文本框应该更新绑定属性,即使它是普通的“vanila”属性。请注意,默认情况下,焦点必须离开文本框才能更新绑定。The source property does not need to be a dependency property nor does the class that exposes it need to implement
INotifyPropertyChanged
.If you have the binding on the
TextBox
set to use theTwoWay
mode editing the text box should update the bound property even if it is a plain "vanila" property. Note by default the focus has to leave the TextBox in order for the binding to update.如果您的业务对象在您要更新的属性上有
set
方法,则应该更新该值,前提是您输入的值不会触发异常。不实现 INotifyPropertyChanged 只会阻碍视觉反馈。
If your business object has a
set
method on the property you want to update, then the value should be updated, provided the value you enter doesn't trigger an exception.Not implementing
INotifyPropertyChanged
hinders just visual feedback.