Access control directly through member variables

In my projects, I have many UserControls that contain other controls. Most of them are tied to the ViewModel, but sometimes I also access them directly from the code to add special functions, and sometimes to save the ViewModel.

If I do this, I always do this directly through the control member variable.

This is mistake? Is there any reason to do this wrong, but go on FindName? I should note that he is sure that the designer will never graphically โ€œoptimizeโ€ these applications.

0
wpf
source share
1 answer

If you mean that you are accessing the control through the name defined in XAML:

<TextBox Name="SomeName" ... /> 

Then this is the right way.

+2
source share

All Articles