Erik Kerber
Erik Kerber

Reputation: 5656

What is the reason for IBOutlets being private in Xamarin.iOS

The generated designer.cs properties are private by default (at least without manual tweaking of generated code). This makes coding against something like a UITableViewCell feel much different than if I were doing this in Objective-C.

The popular way in the case of UIxxxViewCells, at least from what I can tell, is for the UIxxxViewDataSource to populate the IBOutlet properties, and that the cell should only be responsible for anything related to drawing/rendering the view.

With Xamarin.iOS, we are unable to access these properties from the data source, and instead are required to provide additional setter methods to populate the cell. In this way, the cell is responsible for setting it's own properties.

Is this just "The .NET way" of doing things?

Upvotes: 3

Views: 1338

Answers (2)

Mikayla Hutchinson
Mikayla Hutchinson

Reputation: 16153

It's so that we don't break encapsulation by default.

The outlets belong to the object they're on, it should be able to choose whether they're able to be modified from the outside. The fact that they're properties is an implementation detail of the Xamarin.iOS outlets system - you should think of them as private fields.

If you wish to expose them, you can create properties that do so - preferably read-only.

Upvotes: 8

jstedfast
jstedfast

Reputation: 38563

It was probably done that way because that's how the other GUI designers in MonoDevelop worked at the time (still do). Auto-generated bindings to the native controls used by the user-designed control for toolkits like Gtk# are also created as private.

I'm not sure if other UI designers for .NET work (I've never used Visual Studio to develop GUI apps using Windows.Forms or WPF).

Feel free to file a feature request on https://bugzilla.xamarin.com to make them public - I'll gladly implement it, I think it probably makes more sense for them to be public. I haven't changed it mostly because no one has expressed that they wanted it be any other way.

Upvotes: 3

Related Questions