WPF 的 ElementName 在 ContextMenu 中无法绑定成功?试试使用 x:Reference!


在 Binding 中使用 ElementName 司空见惯,没见它出过什么事儿。不过当你预见 ContextMenu,或者类似 Grid.Row / Grid.Column 这样的属性中设置的时候,ElementName 就不那么管用了。

本文将解决这个问题。


本文内容

      • 以下代码是可以正常工作的
      • 以下代码就无法正常工作了
      • 使用 x:Reference 代替 ElementName 能够解决
        • 参考资料

c# - WPF databinding error in Tag property - Stack Overflow