第一个win phone 7程序
silverlight for win phone 7,学习用silverlight开发win phone 7程序,照着视频做出了自己的第一个win phone 7 程序。
程序叫邮编查询小工具,功能是简单的通过输入邮编查询地址。
(1)开发这个小工具,首先要做的是设计界面,很简单,用了两个textblock,两个textbook和一个button控件。
(2)写了一个公共类,叫PostCodeQuery,cs,编写的一些代码不是很懂。
public class PostCodeQuery
{
private static readonly PostCodeQuery instance = new PostCodeQuery();
private Dictionary<int,string> postcodes=new Dictionary<int,string>();
public static PostCodeQuery Instance
{
get
{
return instance;
}
}
private PostCodeQuery()
{
postcodes[100142]="钓鱼台";
postcodes[100031]="天安门";
}
public string GetAddressByPostcode(int postcode)
{
string str="没找到";
if(postcodes.ContainsKey(postcode))
{
str=postcodes[postcode];
}
return str;
}
}
(3)在button的click事件里的代码
int postcode = Convert.ToInt32(PostcodeTextBox.Text);
AddressTextBox.Text = PostCodeQuery.Instance.GetAddressByPostcode(postcode);
(4)程序运行如图: