Binding WPF ContextMenu MenuItem to UserControl Property vs ViewModel Property

前端 未结 1 1216
醉酒成梦
醉酒成梦 2021-01-01 05:43

I\'m struggling to understand what is going on with the ContextMenu. I know it is rendered as a separate window, with a separate visual tree, so we can\'t use relative bindi

相关标签:
1条回答
  • 2021-01-01 06:26

    The second binding works because of so called "inheritance context". You can read about it here: http://blogs.msdn.com/b/nickkramer/archive/2006/08/18/705116.aspx. Basically this is a kind of special case where some properties inherit data context of the owner object. Thus, for example, the inheritance context always works on properties of type Freezable (another interesting article about Freezables: http://drwpf.com/blog/category/freezables/).

    Actually the article says that the inheritance context doesn't work on ContextMenu, but in version 4 they added it, so it actually works now as you've shown it in your example.

    0 讨论(0)
提交回复
热议问题