I\'m planning a WPF application which will
You will have to write data templates for your various field data types so that WPF will chose how to display your data depending on its type. something of this format:
NOTE: This is not WPF just pseudo code
<DataTemplate DataType="{x:Type DateTime}">
<DatePicker Value="{Binding}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type String}">
<TextBox Text="{Binding}"/>
</DataTemplate>
It doesn't have to be a primitive type. It can be an Email
, DateApproved
or even a Url
class type. e.g.
class Customer
{
public Email Email{get;set;}
public DateTime DateApproved{get;set;}
public URI Url{get;set;}
}
public class Email
{
public string Type{get;set;}
public string Value{get;set;}
}
..etc...
Update
Check out this WPF Dynamic UI example on MSDN: Dynamic Data Entry with WPF and LINQ
You need to setup a DataTemplate for each field type eg Date, String, Bool. This will determine how each field will appear.
You could then use the columns for a database query to generate a list of objects and place them into an ItemsControl.
ObservableCollection<ColumnDef> columns = new ObservableCollection<ColumnDef>();
// Add columns from DB
columns.Add(new StringColumnDef{Object=..., Field=..., Label=..., Value=...});
columns.Add(new DateColumnDef{Object=..., Field=..., Label=..., Value=...});
items.ItemsSource = columns; // items is an ItemsControl
Each item in the item control will display based on the DataTemplate for that type.
Inside the ColumnDef you could use Reflection to update the data object with changes from the UI controls. You can then apply the changes to the databae when the user saves.