Bind DataGridColumns Header to DataContext of the window

后端 未结 1 872
[愿得一人]
[愿得一人] 2021-01-23 12:31

I have a DataGrid and want to bind the Header-property to a property of my windows DataContext but I did not get it working.

Bindi

1条回答
  •  旧巷少年郎
    2021-01-23 13:21

    Since DataGridTextColumn or any other supported data grid columns are not part of visual tree of datagrid so they don't inherit the DataContext of datagrid. Since, they don't lie in visual tree so any try to get DataContext using RelativeSource won't work.

    Solution - You can create a proxy element to bind the data context of window/control; use that proxy element to bind the Header of DataGridTextColumn.

    
       
           
       
           
           
              
                  
              
         
    
    

    0 讨论(0)
提交回复
热议问题