You absolutely cannot just make that control public. Controls in .NET are private member variables of their Form, Page, Window, etc. They are generated by the compiler into the appropriate "hidden" cs file, and are set to private at that point. You can expose them though, with a property that returns them:
public MyControl MyControlProperty { get { return myControlName; } }
Now, you should really never be doing this. Other classes shouldn't know the internals of your view classes, they should be invoking methods, changing data, etc to cause those internals to change.
Also, as this is WPF, you shouldn't even be doing that, instead you should use view models that can invoke methods on other view models (often through a model) to cause their associated views to react and update.
In short, yes, you can expose controls to the world, but if you have to do so, you are almost assuredly doing it totally wrong.
Partager