强制绑定更新Silverlight [英] Force Binding Update Silverlight

查看:98
本文介绍了强制绑定更新Silverlight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制我的对象DataContext绑定更新?我在网格上使用一个事件,绑定更新在我的事件触发之前没有被处理。

How can I force my objects DataContext bindings to update? I'm using an event on a grid, and binding updates are not being processed before my event fires.

有什么便宜的技巧来解决这个问题?
最后,我可以随时从旧的手动方式获取我的文本框中的值并更新我的对象,但是对于我来说,绑定会很好。

Any cheap tricks to get around this? In the end I can always do things the old manual way of getting the values from my textboxes and updating my object, but it'd be nice to have binding do it for me.

更新

我的网格包含两个文本框。如果用户点击网格(MouseButtonUp事件),那么我保存更改。但是在我的MouseButtonUp事件处理程序中,数据文本不是最新的。我想象是因为一个文本框只会在焦点丢失时更新。

My grid contains two textboxes. If a user clicks on the grid (MouseButtonUp event) then I save the changes. But in my MouseButtonUp event handler, the datacontext is not up to date yet. I'd imagine it's because a text box only updates when focus is lost.

推荐答案

您可以强制更新源代码通过调用UpdateSource()方法绑定绑定。尝试在保存之前将其添加到MouseButtonUp事件处理程序。

You can force an update of the source a binding by calling the UpdateSource() methond on on the binding. Try adding it to the MouseButtonUp event handler just before saving.

像这样:

BindingExpression binding = FirstTextBox.GetBindingExpression(TextBox.TextProperty)
if (null != binding) binding.UpdateSource();

您可以在MSDN上找到有关此信息的更多信息: http://msdn.microsoft.com/en-us/library/system .windows.data.bindingexpression.updatesource(VS.95).aspx

You can find more information about this on MSDN: http://msdn.microsoft.com/en-us/library/system.windows.data.bindingexpression.updatesource(VS.95).aspx

这篇关于强制绑定更新Silverlight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆