且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

wpf向上绑定:绑定到嵌套uiElement中的视图模型属性

更新时间:2021-10-10 03:04:19

此处有一条评论,说:

只是要在此处说明如果要绑定到那么您必须明确指定RelativeSource的DataContext :{Binding Path = DataContext.SomeProperty,RelativeSource =....这是当我尝试绑定到一个新手时,对我来说有些意外父对象在DataTemplate中的DataContext.

Just wanted to note here that if you want to bind to a property in the DataContext of the RelativeSource then you must explicitly specify it: {Binding Path=DataContext.SomeProperty, RelativeSource=.... This was somewhat unexpected for me as a newbie when I was trying to bind to a parent's DataContext within a DataTemplate.

此评论值得更多关注,因此我将其用作正确答案.

This comment deserves more attention, so I'll use it as the correct answer.