Monotouch Frame dimensions can't be set directly?
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 开发者_如何学JAVAprotect against arcane programming styles?
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.
精彩评论