I am trying to get the name of the property associated with a particular DataGridColumn
, so that I can then do some stuff based on that. This function is called whe
For me, ClipboardContentBinding
of DataGridTemplateColumn
is a solution:
Private Function FindBoundProperty(ByVal col As DataGridColumn) As String
Dim boundColumn As DataGridBoundColumn = TryCast(col, DataGridBoundColumn)
Dim boundPropertyName As String = ""
Dim binding As Binding
If col.DependencyObjectType.Name = "DataGridTextColumn" Then
binding = TryCast(boundColumn.Binding, Binding)
boundPropertyName = binding.Path.Path
End If
If col.DependencyObjectType.Name = "DataGridTemplateColumn" Then
binding = TryCast(col.ClipboardContentBinding, Binding)
boundPropertyName = binding.Path.Path
End If
Return boundPropertyName
End Function