Wpf 如何在Xaml中将对象绑定到DataGridRow?

Wpf 如何在Xaml中将对象绑定到DataGridRow?,wpf,data-binding,mvvm,viewmodel,wpfdatagrid,Wpf,Data Binding,Mvvm,Viewmodel,Wpfdatagrid,存在一个DataGrid,其中ItemsSource作为ObservableCollection。ParticipantViewModel具有名为ExpenseType、Currency等的属性。对于某些特定的费用类型,参与者可以更改货币,这可以通过ParticipantViewModel的另一个名为IsCurrencyEnable的属性来确定。我使用ComboBox IsEnabled属性绑定IsCurrencyEnable 但它正在MainViewModel中搜索IsCurrencyEnab

存在一个DataGrid,其中ItemsSource作为ObservableCollection。ParticipantViewModel具有名为ExpenseType、Currency等的属性。对于某些特定的费用类型,参与者可以更改货币,这可以通过ParticipantViewModel的另一个名为IsCurrencyEnable的属性来确定。我使用ComboBox IsEnabled属性绑定IsCurrencyEnable

但它正在MainViewModel中搜索IsCurrencyEnable,而不是ParticipantViewModel

如何绑定IsEnabled属性,使其从ParticipantViewModel获取值


谢谢。

这很可能是datacontext问题。您需要绑定以下内容

{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ControlTypeThatBindsToParticipantViewModel}},Path=DataContext.IsCurrencyEnable}
ControlTypeThatBindStopParticipantViewModel这是将其数据上下文绑定到ParticipantViewModel的控件类型,可以是window、usercontrol等


希望这有助于发布相关代码和XAML。您好,谢谢回复。DataGrid ItemSource的类型为ObservableCollection(MainViewModel的属性)。DataGrid的每一行都显示ParticipantViewModel属性的databind,因此它的DataGridRow控件绑定到ParticipantViewModel。但是当我使用{Bind IsCurrencyEnable}时,它会在MainViewModel中搜索IsCurrencyEnable属性。您确实需要像HighCore建议的那样发布xaml代码,否则我们将无能为力。你试过我的解决方案吗?