axb*_*eit 3 c# field properties xamarin xamarin.forms
我目前通过Xamarin书自己工作.在那里你可以看到这个代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Xamarin.Forms;
namespace BookCode
{
public class Greetings : ContentPage
{
public Greetings()
{
Label label;
label = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
Content = label;
SizeChanged += OnPageSizeChanged;
void OnPageSizeChanged(object sender, EventArgs args)
{
label.Text = String.Format("{0} \u00D7 {1}", Width, Height);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在代码的解释中,您可以阅读:
"相反,事件处理程序访问Label元素(方便地保存为字段)以显示页面的Width和Height属性.Btring.Format调用中的Unicode字符是一个时间(×)符号."
我目前对领域和属性的了解基本上是这样的:
public class ClassName
{
private string field;
public string property {get {return field;} set {field = value;} }
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么Label元素被保存为字段.它可以保存为其他东西吗?
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |