我需要将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上 -
我已经在文章中设置了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>
但是,为什么它会知道元素“名称”?
干杯