0

Hi in a DataGridTextColumn I am binding to a new DataContext which works

    <DataGridTextColumn Header="Name" IsReadOnly="True" 
           Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}},Path=DataContext.CollectionName}"  Width="150">

However, the TextBox says "(Collection)" so is there a way to display a properly within the Collection?

In a DataGridComboBox you state:

<Setter Property="DisplayMemberPath" Value="PropertyName"/>

But you dont have this property in a DataGridTextColumn.

Thanks

user3428422
  • 4,300
  • 12
  • 55
  • 119

1 Answers1

0
"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}},Path=DataContext.CollectionName.PropertyName}"

should bind to the given PropertyName

0x8BADF00D
  • 962
  • 1
  • 8
  • 18
  • I thought that too (I agree the logic is right, but it never worked) – user3428422 Apr 16 '14 at 14:17
  • Well, I also think that your whole binding is not necessary at all. Is there any reason for this? What are you trying to archive? – 0x8BADF00D Apr 16 '14 at 14:18
  • I have done it now, but, I have 2 combo boxes that the itemsource is different to the itemsource of the DataGrid. So whenever a user selects a ID in the combobox, I wanted the name of this ID to appear in the DataGridTextColumn, but the problem is, the DataGridTextColumn is binded to the DataContext of the DataGrid so I couldn't achieve this. The DataContext has to be the one of the combo box – user3428422 Apr 16 '14 at 14:24
  • Where is the problem? If you bound a `ObservableCollection` to your DataGrid, you could simply add a new entry and the DataGrid changes (assuming you implemented `INotifyPropertyChanged` correctly) – 0x8BADF00D Apr 16 '14 at 14:28