Thursday, February 10, 2011

Children Controls Are Inaccessible Due to Access Modifier

When I create a user control in WPF it would appear that all the children of this control are declared as internal? I've not been able to verify this, nor finding any resources discussing this matter at all.

I can access the controls in the same assembly, but not in a project referencing the assembly where the user control is located. Is there a way to override the default access modifier of child controls in XAML so I don't manually have to expose the controls via properties in the user control?

  • Have you tried to set the x:FieldModifier attribute of your children controls to "public"?

    Qua : Worked like a charm.
  • However, just making them public, is no good idea - its really bad design.

    You should expose their real data through properties of your UserControl. The best thing would be introducing an interface.

    Another solution (more the "WPF-way") would be using the data-context as the only property which is accessed from outside: The controls could bind to the properties they need.

    From winSharp93

0 comments:

Post a Comment