WPF - How to bind a DataGridTemplateColumn

后端 未结 5 678
予麋鹿
予麋鹿 2021-02-05 07:07

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

5条回答
  •  天涯浪人
    2021-02-05 07:19

    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
    

提交回复
热议问题