Datagrid binding in WPF

后端 未结 3 1885
灰色年华
灰色年华 2020-11-27 16:56

I know this has been asked already but I have done almost everything what is suggested by developers.



        
3条回答
  •  情深已故
    2020-11-27 17:48

    Without seeing said object list, I believe you should be binding to the DataGrid's ItemsSource property, not its DataContext.

    
                        
            
            
       
    
    

    (This assumes that the element [UserControl, etc.] that contains the DataGrid has its DataContext bound to an object that contains the list collection. The DataGrid is derived from ItemsControl, which relies on its ItemsSource property to define the collection it binds its rows to. Hence, if list isn't a property of an object bound to your control's DataContext, you might need to set both DataContext={Binding list} and ItemsSource={Binding list} on the DataGrid...)

提交回复
热议问题