WPF 在绑定失败时应用触发器
这个问题是这个问题的后续问题...
我是绑定到异构对象集合,并非所有对象都具有相同的属性集。我正在数据网格中执行此操作。如果绑定失败,我想使单元格变灰。如果绑定失败,有没有办法应用触发器?
编辑:下面的答案适合我的目的,但我跟进了 这个问题因为我想知道如何做到这一点(以非黑客方式 - 我确实喜欢黑客,但不要误会我的意思)
This question is a follow on from this one...
I am binding to a heterogeneous collection of objects, not all objects have the same set of properties. I am doing this in a datagrid. I would like to gray out the cell if the binding fails. Is there a way to apply a trigger if a binding fails?
EDIT: The answer below was suitable for my purposes, but i followed up with this question because I would like to know how to do it (in a non hack fashion - i do love the hack however, don't get me wrong)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,你不能直接这样做。但是,如果您可以识别永远不会从成功绑定中返回的值,则可以创建一个 DataTrigger,其绑定将该值作为其 FallbackValue,并在同一值上触发:
理论上,可以省略 FallbackValue 和触发器在
{x:Static DependencyProperty.UnsetValue}
上,这会更干净,但这在实践中似乎不起作用。As far as I know, you can't do this directly. However, if you can identify a value that will never be returned from successful bindings, you can create a DataTrigger whose binding has that value as its FallbackValue, and trigger on that same value:
In theory it might be possible to omit the FallbackValue and trigger on
{x:Static DependencyProperty.UnsetValue}
, which would be much cleaner, but this doesn't appear to work in practice.