简体   繁体   中英

Add UserControl to WPF DataGrid Cells

I need to add my UserControl to DataGridCells in WPF. I bind data to DataGrid in my code, not in XAML. So ho to do this in code, not in XAML?

Is your question about a DataGrid or a UserControl?

In my understanding, a UserControl is in the each DataGrid row. Or we can say, the parent of UserControl is a DataGrid element and the binding of the DataGrid is done in code.

Whether the data binding of DataGrid (not DataGridCell) is defined in code or in XAML, the only thing you need to consider is the data at each row which the contained element (a UserControl) affected.

So, you only need to consider "how to display each data in UserControl", not related with the DataGrid.

To add UserControl in DataGridCell, this link will give you a great reference: http://www.wpftutorial.net/DataGrid.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM