1

Editing UI Frame properties directly don't seem to work.

i.e.

scrollView.ContentSize.Width = 100;

doesn't work but

RectangleF scrollFrame = ScrollView.Frame;
scrollFrame.Width = width * pageCount;
ScrollView.ContentSize = scrollFrame.Size;

does! Why is this? Isn't Monotouch supposed to protect against arcane programming styles?

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
angel of code
  • 686
  • 8
  • 25

1 Answers1

4

This is basic C# behavior.

The ContentSize property is a SizeF which is a struct (=value type) and not a class (=reference type).

Calling

scrollView.ContentSize.Width = 100;

does not work because you are setting a value on a property of a copied object.

Calling

scrollFrame.Width = width * pageCount;

works because although RectangleF is also a struct, you are setting a value on the actual object.

Likewise,

ScrollView.ContentSize = scrollFrame.Size;

creates a copy, but sets a new object after the '=' and works correctly.

Dimitris Tavlikos
  • 8,170
  • 1
  • 27
  • 31