Binding to property in owning window's viewmodel within a DataTemplate in Window.Resources

若如初见. 提交于 2019-11-30 23:25:55
Yazan Al-Alul

I have found the answer here:

So all I had to do to access the window's DataContext was set:

Source={x:Reference Name=Root}

An explanation of why ElementName does not work in this case is found here. Specifically:

Probably the simplest example of where we don't have inheritance context links is across > random property elements:

<Button>
  <Button.ContextMenu>
    <ContextMenu/>
  </Button.ContextMenu>
</Button>

ContextMenu is neither a visual nor logical child of Button, nor is it one of the inheritance context cases listed above (ContextMenu is not a Freezable).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!