KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a WPF application with MVVM pattern. In one of my view, I have to bind an ObservableCollection to view. In that view, I have one ListBox and one DataGrid both bind to the same ObservableCollection but doing different things like events, style etc.. I need only one of these controls displayed at a time and what I did is created two user controls, one for DataGrid and other for ListBox . And I switched between them by placing a ContentControl on the main view(something similar to this blog . The default view is DataGrid and when click on a button the other view is displayed(i.e. ListBox ). Up to this are working fine. One more thing to keep in mind that the Data Grid columns are generated dynamically by using the solution described in the following link . So when I go back to DataGrid view it's throwing an error while adding columns to Data Grid in foreach statement (pls refer the answer of the previous link) like "DataGridColumn with Header 'Ord' already exists in the Columns collection of a DataGrid . DataGrids cannot share columns and cannot contain duplicate column instances." But I'm sure that before adding columns to DataGrid its Count property is zero(dataGrid.Columns.Count()). So how the DataGrid header properties are persisted? Is there any way to clear the header values?. Please suggest...
Tags (comma-separated)
Save Edits
Cancel