Is there a smart pattern for nullable parameters using data binding?

In my application, I have controls bound to properties of an object.

But the controls always look like this:

  • Checkbox
  • Shortcut that explains the setting
  • Edit control (ex: text box)

If the checkbox is unchecked, I use the anchor to disable the textbox.

If the checkbox is unchecked, I want the property value to be null.

If the checkbox checked, I would like the property to contain the value from the textbox.

A text field can be NumericUpDown

, ComboBox

, DatePicker

, etc.

Is there a sane way to get this behavior using binding, or is this my only option?

I would really like to create a control that supports this and reuse it.

0


source to share


1 answer


It looks like you want to bind to a custom object that had a "UseNull" property as well as a base property.

The "real" control for non-zero values ​​can then be selected using the TemplateSelector.



At least that's how I initially attacked this issue.

+1


source







All Articles