Best practice for binding user control data - how to do it?

I have User Control with TextBoxes, Labels, .... Now I would like to get the same data binding functions as I would place controls directly on the form. I tried using an additional binding source and error provider in User Control, and I tried to make the properties of my controls available as a property.

Nothing succeeded. Therefore, there must be a solution to do this. So how?

+3
source share
2 answers

I demonstrated a sample at https://github.com/edymtt/usercontrolwithdatabinding to illustrate some data binding scenarios that may apply to your question. In particular, I examined two scenarios:

  • Implementation UserControlfor editing a basic property (string, integer, ...);
  • An implementation UserControlfor editing properties of a complex type (for example, AddressPOCO);

Implementation UserControlfor editing the main property

(, Text TextBox) , ( , TextChanged TextBox TextChanged, . MSDN " ".

ErrorProvider ( ) UserControl

UserControl

, :

  • BindingSource Error Provider usercontrol POCO;
  • .

, , , .

+1

- , , DependencyProperty User Control, .

0

Source: https://habr.com/ru/post/1756864/


All Articles