Fluent-based data forms for WPF
https://www.nuget.org/packages/WPF.DataForms
- Every form has groups and fields
- Every form has three states (view, create and edit)
- Every field create different controls depended by state
- View state: e.g. some controls are just disabled or replaced by non-editable controls.
- Automatic grid layout
- add or move fields and groups without setting the row and column number
- Easily replace controls without changing mappings
- Create the entity detail viewmodel
class CustomerDetailViewModel
{
public Customer Customer { get; set; }
public DataTemplate DataTemplate { get; set; }
//..
}
- Create the entity detail view and set the data context to the viewmodel instance.
<ContentControl Content="{Binding}"
ContentTemplate="{Binding DataTemplate}"
/>
- Define the mapping for viewmodel
class CustomerFormMapping : DataFormMapping<CustomerDetailViewModel>
{
public override void CreateContent()
{
MainContent.Group(Resources.General)
.Id(Resources.Id, x => x.Customer.Id)
.Bool(Resources.IsActive, x => x.Customer.IsActive)
.Text(Resources.Title, x => x.Customer.Title)
.Text(Resources.LastName, x => x.Customer.Lastname)
.Text(Resources.FirstName, x => x.Customer.Firstname)
.Date(Resources.DateOfBirth, x => x.Customer.DOB)
;
}
- Create the data template:
viewModel.DataTemplate = new CustomerFormMapping ().CreateTemplate(FormState.View);