//随机9个不同的数
int[] u=new u[9];
private void suijishiyan() {
Random rand = new Random();
for (int i = 0; i < 9; i++)
{
u[i] = rand.Next(1,15);
for (int l = 0; l < u.Length; l++)
{
if (i == l) {
}
else if(i!=l)
{
if (u[i] == u[l])
{
u[i] = rand.Next(1,15);
l = -1;
continue;
}
}
}
}
}
WP7
去除数组中重复的值,只保存一个值
string[] xx1 = name.Split('|');
int chongfupd = 0;
string jiajia = "";
for (int i = 0; i < xx1.Length; i++)
{
chongfupd = 0;
for (int l = i; l < xx1.Length; l++)
{
if (xx1[l] == xx1[i])
{
chongfupd++;
}
}
if (chongfupd > 1)
{
}
else {
jiajia =jiajia+ xx1[i] + "|";//最后结果
}
}
传值
NavigationService.Navigate(new Uri("/页面导航/Page2.xaml?name=yzk&age=18",UriKind.Relative));
接值
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string name = NavigationContext.QueryString["name"];
int age = Convert.ToInt32(NavigationContext.QueryString["age"]);//QueryString中取出的值是String类型
PageTitle.Text = name + age;
}
图片路径问题
img1.Source =new BitmapImage(new Uri("images/3.jpg", UriKind.Relative));
加速度
Accelerometer acc=new Accelerometer();
acc.ReadingChanged+=.....;
acc.Start();
void ...()
{
//ReaddingChanged不是在ui线程触法的
Dispatcher.BeginInvoke<()=>{
textBlock1.Text=""+e.X+e.Y+e.Z;
}
}
计时器
private void button1_Click(object sender, RoutedEventArgs e)
{
DispatcherTimer timer1 = new DispatcherTimer();
timer1.Interval = TimeSpan.FromMilliseconds(1000);//间隔时间
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
void timer1_Tick(object sender, EventArgs e)
{
// stw.Angle += 10;
}
照相机功能
private void button1_Click(object sender, RoutedEventArgs e)
{
CameraCaptureTask cccc = new CameraCaptureTask();
cccc.Completed += new EventHandler<PhotoResult>(cccc_Completed);
cccc.Show();
}
void cccc_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage img=new BitmapImage();
img.SetSource(e.ChosenPhoto);
img1.Source = img;
}
}
图片选择器
private void button1_Click(object sender, RoutedEventArgs e)
{
PhotoChooserTask pacTack = new PhotoChooserTask();//
pacTack.Completed += new EventHandler<PhotoResult>(pacTack_Completed);
pacTack.ShowCamera = true;//启用照相功能,即没有想要的图片时可以选择拍摄
pacTack.Show();
}
void pacTack_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage img = new BitmapImage();
img.SetSource(e.ChosenPhoto);
image1.Source = img;
}
}