0

I need to bind a DataGridTextColumn to a different DataContext, I know this is possible as I am doing this correctly in a DaatGridComboBox. the code I have at the moment is

       <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>

What I have done wrong?

---- On bindingProxy --

I have setup the BindingProxy class how it is in the article. And have this

       <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>

However, why would it know the element "Name"?

Cheers

Community
  • 1
  • 1
user3428422
  • 4,300
  • 12
  • 55
  • 119

1 Answers1

0

You can use BindingProxy, you can bind to data when the DataContext is not inherited