Child control unavailable due to access modifier

When I create a user control in WPF, does it seem that all the children of this control are declared as internal? I could not verify this and did not find any resources that generally discussed this issue.

I can access the controls in the same assembly, but not in the project referencing the assembly where the user control is located. Is there a way to override the default access modifier for child controls in XAML, so I don’t need to manually set the controls through the properties in the user control?

+3
source share
2 answers

Have you tried setting the attribute of x:FieldModifieryour child controls to " public"?

+9
source

However, just making them publicly available is not a good idea - it is a really bad design.

You must disclose your real data through the properties of your UserControl. The best thing would be to introduce an interface.

Another solution (a more "WPF path") will use the data context as the only property that is accessed from the outside: controls can bind to the required properties.

+1
source

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


All Articles