今天知道了几件事情,由于对C#还是比较生疏的,最近生在恶补
学了几天的WPF才发现WP7并不需要WPF,而是用的是silverlight(银光技术),让我很晕啊,还要C#跟JAVA是比较相似的,这就让我放心很多了,但是银光技术还是陌生的,所以需要从新学习。
tips:
String message = "Hello";
MyTextBox.Text = message + " World";
上面的那句话等同于
MyTextBox.Text = String.Format("{0} World",message);
好,现在开始写程序
1、打开VS2010 express for windows phone,创建一个Application,名字叫做“Test”
2、在可视化设计界面里设计一个小程序,里面有两个TextBlock,一个TextBox,一个Button,如图
3、为这些组件设置响应的属性,注意,将TextBlock的属性中的TextWrapping设置为Wrap,而不是NoWrap,其实设置为Wrap的意思就是里面的文字自动换行的意思
4、点击Button控件,进入代码中,编写代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace Test
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
String valueText = textBox1.Text;
if (valueText == "1")
{
textBlock2.Text = "你赢得了一辆宝马!";
}
else if(valueText == "2")
{
textBlock2.Text = "你捡到了一部手机";
}
else if (valueText == "3")
{
textBlock2.Text = "你得到了100万人民币";
}
else
{
textBlock2.Text = "你失败了,很失败!";
}
}
}
}
5、运行:点击绿色图标或者(Ctrl+F5)