Monotouch Frame 尺寸不能直接设置? [英] Monotouch Frame dimensions can't be set directly?

查看:32
本文介绍了Monotouch Frame 尺寸不能直接设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直接编辑 UI 框架属性似乎不起作用.

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

scrollView.ContentSize.Width = 100;

不起作用但是

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

可以!为什么是这样?Monotouch不应该保护反对神秘的编程风格?

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

推荐答案

这是基本的 C# 行为.

This is basic C# behavior.

ContentSize 属性是一个 SizeF,它是一个结构(=值类型)而不是一个类(=引用类型).

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

打电话

scrollView.ContentSize.Width = 100;

不起作用,因为您正在为复制对象的属性设置值.

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

打电话

scrollFrame.Width = width * pageCount;

之所以有效,是因为虽然 RectangleF 也是一个结构体,但您是在实际对象上设置一个值.

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

同样,

ScrollView.ContentSize = scrollFrame.Size;

创建一个副本,但在 '=' 之后设置一个新对象并正常工作.

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

这篇关于Monotouch Frame 尺寸不能直接设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆