Should User Controls be supported by properties?

I hope I am saying this correctly. I have a WinForm application (3.5) that has 1 form, which is divided into two regions. 1 is Navigation and the other is Panel, this is Content. You choose what you want in the "Navigation" section, i.e. Demographic data, and then embed the UserControl element that contains all the Demographics controls in the panel.

I ask if each user control should have one Propertyfor everyone Control. Example: ucDemographics has a text box with a name txtCity. Should I Propertystore valuein txtCityand allow access to my form and other user controls?

Is this a common "best practice"?

If not, then what?

+3
source share
2 answers

It depends on what you want to achieve with UserControl.

Normally, you will not set txtCity, because the caller can manipulate all the contents of the text field. In most scenarios, you should only expose the current text la

public string CityText
{
    get { return this.txtCity.Text; }
}
+5
source

, . . "" , , . , - , UserControl, .

+2

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


All Articles