是否可以“刷新”WPF数据绑定 [英] Is it possible to 'refresh' WPF data bindings

查看:247
本文介绍了是否可以“刷新”WPF数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xaml TabControl,在一个页面上,有3个RadioButton每个绑定到相邻ListView的选定值的不同属性。在ListView中选择的项目进行切换后,我的单选按钮似乎忘记了它们的绑定并且不刷新。



所以在调试器中看时,当我切换到一个新的选定项目,我看到非用户代码首先检查所有3个属性的值,然后只有前两个,最终只有第一个。但是,如果我更改标签并更改,似乎给了我另外一些用途。



绑定本身是非常简单的。一个布尔属性的TwoWay绑定到IsChecked。它是4级深度(Path = DataModel.Selected.AB),但我有其他的东西在相同的深度,工作正常。



这是人们听到的和知道可能会发生什么?或者如果绑定在某种程度上被忘记了,有没有办法明确提醒xaml?

解决方案

这显然是一个已知问题:



http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8eb8280a-19c4-4502-8260-f74633a9e2f2/

I've got a xaml TabControl and on one page, there are 3 RadioButtons each bound to a different property on the selected value of an adjacent ListView. After switching between selected items in the ListView, my radio buttons seem to forget they're bound and don't refresh.

So watching it in the debugger, when I switch to a new selected item, I see the non user code first checking the value on all 3 properties, then only the first two, and eventually only the first. However, if I change the tab and change back, it seems to give me another few uses.

The binding itself is fairly straightforward. a TwoWay binding of a bool property to IsChecked. It's 4 levels deep (Path=DataModel.Selected.A.B), but I have other things at the same depth that work fine.

Is this something people have heard about and know what might be going on? Or if the binding is somehow getting forgotten, is there a way to explicitly remind the xaml?

解决方案

This is apparently somewhat of a known issue:

http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8eb8280a-19c4-4502-8260-f74633a9e2f2/

In short, a RadioButton (through .Net 3.5sp1) somehow kills bindings of other RadioButtons when when it's checked while trying to uncheck any other buttons. The simple fix (read: hack) is to assign each radiobutton a different GroupName and then they don't try to mess with eachother

这篇关于是否可以“刷新”WPF数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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