I need to create an application that will take an .ini file which will contain
- min
- max
- default
values for the elements, allows user to edit these values and save a new .ini file. Since .ini files can not contain different elements in the specified groups the GUI needs to be generated dynamically.
From what I have read about WPF it largely stands on data-binding and Notifying Property changes.
Since my view model needs to accommodate different numbers of variables I am not going to have the ability to bind to properties, i was planning to attach one event handler to all text boxes which will pick the corresponding validation rule when the TextBox loses focus or Enter is pressed. After that, it should update the model accordingly if it passes validation and update the View using the model for the corresponding value.
I was wondering whether this sounded like a valid idea, whether there is similar design pattern I should read about or should I just steer away from WPF altogether?
You can still use bindings – since WPF supports item templating, and since you are using an MVVM pattern you can just create a VM for each sub-item in the list (you don’t even need to do this you can bind directly in the template of each list item to a DTO or business object)
I’m currently doing a similar thing now – I have a list of material tests for a client, they want to have a variable number and type of tests for each material, but also be able to tweak and change those tests per order for their customer
They actually have two test types, but to describe the simpler of the two cases (which doesn’t require child VMs as such) I just created an
ItemsControlthat has an item template:In this case the model just contains a list of property names/values and displays them in a stackpanel (you may need to set the
ItemPanelusing anItemsPanelTemplate. Obviously you could have an extendedItemsControlthat allows aDataTemplateSelectorto display a different data template per type (in fact WPF already support per-type data templates).I’m currently using Caliburn.Micro which actually does a lot of setting up child-templates for you – so if you create the bound items as a VM you can do something as simple as this:
And CM takes care of the rest as long as the child items in the
SomeBindingproperty are VMs themselves (though that’s another story :P)