I am a programmer for winforms and asp.net. A new-comer to WPF application development.
I wish to thank in advance for any help rendered to my query,
I am working on a application for Banking. My job profile is to develop reusable usercontrols for the application.
An example would be to make a Simple numeric input box which has Max and Min number properties. So the control pops an error if the number entered is not within a range. (ofcourse there is much more to this control 🙂
On similar lines. I have to develop a listview user control with Two properties.
1) A comma separated values of column headers
2) A comma separated values of data to add
My colleague, now places this usercontrol on window (as known in WPF). and passes the above parameters to the listview control.
My coding ensures that the columns are placed and data is added. In winforms this is a simple process. In WPF i was able to achieve it for known columns by defining beforehand in observablecollection or otherwise using
SamplelistView.Items.Add(new { FirstName = "test1", LastName = "ABX", EmployeeNumber = "AAA111"});
However in the above mentioned command, Firstname,Lastname are previously known columns.
Is there any command like,adding data as a array or adding data directly to columns without binding to a collection. OR is there a way to add columns to observablecollections at runtime.
Pls. excuse my limited exposure on nomenclature and otherwise.
My approach to this problem would be:
UserControlthat hosts aDataGridColumnNamesdependency property to theUserControl. In thePropertyChangedevent handler, parse the CSV and update theDataGrid.Columnaccordingly.Datadependency property to theUserControl– and when this changes, parse the CSV and add the data to theDataGrid.See this question for a few pointers:
programmatically add column & rows to WPF Datagrid
By the way, a CSV of column names is a horrible interface! Why not expose a
List<string>, then add aTypeConverterso that you can use a CSV string in XAML?