WPF - How to bind a DataGridTemplateColumn

后端 未结 5 668
予麋鹿
予麋鹿 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:14

    It's a tricky one. We achieved the binding by traversing to its grandparent UserControl (we had DataGrid inside a UserControl) and the UserControl was bound to a Presenter (Model in our case). In the code below, check the property SelectedItem of AutoCompleteBox placed inside the DataGridTemplateColumn.

    
      
        
            
                SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},  Path=Model.SelectedStockItem, Mode=TwoWay}">
            
        
      
    
    
    

提交回复
热议问题