我需要将 DataGridTextColumn 绑定到不同的 DataContext,我知道这是可能的,因为我在 DaatGridComboBox 中正确执行了此操作。我现在的代码是
<DataGridTextColumn Header="Name" binding={wont work in here as this element is bounded to the itemsource of the DataGrid} IsReadOnly="True" Width="150">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Text"
Value="{Binding DataContext.CustomerCollection.Name}"></Setter>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
我做错了什么?
---- 在绑定代理上 --
我已经在文章中设置了 BindingProxy 类。有这个
<DataGrid.Resources>
<l:BindingProxy x:Key="proxy" Data="{Binding}" />
</DataGrid.Resources>
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Text"
Value="{Binding Data.Name, Source={StaticResource proxy}}"></Setter>
</Style>
</DataGridTextColumn.ElementStyle>
但是,为什么它会知道元素“名称”?
干杯