How to build dynamic data entry forms in a WPF application?

后端 未结 2 856
醉酒成梦
醉酒成梦 2021-02-04 16:06

I\'m planning a WPF application which will

  • be able to create dynamic data entry forms (meaning the form gets the fields to display, their order, e
2条回答
  •  灰色年华
    2021-02-04 17:02

    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 columns = new ObservableCollection();
    
    // 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.

提交回复
热议问题