Dmitry Arestov
Dmitry Arestov

Reputation: 1668

Hidden public property in WPF control

I am writing a custom control in WPF that works in this way: user sets some property which type is some class. Then, the control examines this object and generates some collection, which is to be displayed in UI via data binding.

In order for data binding to work, this collection should be a public property, but for the sake of incapsulation I do not want it to be public.

What is the best practice in such a situation?

Upvotes: 1

Views: 375

Answers (1)

Alexis
Alexis

Reputation: 825

You can use the Browsable attribute to hide property from property grid and the EditorBrowsable attribute to hide it from the XAML\CS editor. Or you can override the OnApplyTemplate method and assign your property value to the target element. You can get target element using the GetTemplateChild method.

Upvotes: 3

Related Questions