Student.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using Microsoft.Phone.Controls;
  13. using Microsoft.Phone;
  14. using Microsoft.Phone.Tasks;
  15. using System.Windows.Media.Imaging;
  16. namespace IDTemplate
  17. {
  18. public partial class Student : PhoneApplicationPage
  19. {
  20. PhotoChooserTask photo = new PhotoChooserTask();
  21. PhotoChooserTask image = new PhotoChooserTask();
  22. CameraCaptureTask cct = new CameraCaptureTask();
  23. BitmapImage bmp = new BitmapImage();
  24. ImageBrush imgBrush = new ImageBrush();
  25. BitmapImage bmp1 = new BitmapImage();
  26. ImageBrush imgBrush1 = new ImageBrush();
  27. BitmapImage bimg= new BitmapImage();
  28. public Student()
  29. {
  30. InitializeComponent();
  31. }
  32. private void textBox5_Tap(object sender, GestureEventArgs e)
  33. {
  34. textBox5.Text = "";
  35. }
  36. private void textBox1_Tap(object sender, GestureEventArgs e)
  37. {
  38. textBox1.Text = "";
  39. }
  40. private void textBox2_Tap(object sender, GestureEventArgs e)
  41. {
  42. textBox2.Text = "";
  43. }
  44. private void textBox3_Tap(object sender, GestureEventArgs e)
  45. {
  46. textBox3.Text = "";
  47. }
  48. private void image2_Tap(object sender, GestureEventArgs e)
  49. {
  50. cct.Completed += new EventHandler<PhotoResult>(cct_Completed);
  51. try
  52. {
  53. cct.Show();
  54. }
  55. catch (System.InvalidOperationException ex)
  56. {
  57. MessageBox.Show("An error occurred.");
  58. }
  59. }
  60. void photoChooserTask_Completed(object sender, PhotoResult e)
  61. {
  62. if (e.TaskResult == TaskResult.OK)
  63. {
  64. MessageBox.Show(e.ChosenPhoto.Length.ToString());
  65. //Code to display the photo on the page background control named ContentPanel.
  66. bmp.SetSource(e.ChosenPhoto);
  67. imgBrush.ImageSource = bmp;
  68. ContentPanel.Background = imgBrush;
  69. }
  70. }
  71. void imageChooserTask_Completed(object sender, PhotoResult e)
  72. {
  73. if (e.TaskResult == TaskResult.OK)
  74. {
  75. MessageBox.Show(e.ChosenPhoto.Length.ToString());
  76. //Code to display the photo on the page in an image control named Image1.
  77. bmp1.SetSource(e.ChosenPhoto);
  78. imgBrush1.ImageSource = bmp1;
  79. image1.Source = bmp1;
  80. }
  81. }
  82. void cct_Completed(object sender, PhotoResult e)
  83. {
  84. if (e.TaskResult == TaskResult.OK)
  85. {
  86. bimg.SetSource(e.ChosenPhoto);
  87. image2.Source = bimg;
  88. }
  89. }
  90. private void PageTitle_Tap_1(object sender, GestureEventArgs e)
  91. {
  92. try
  93. {
  94. photo.Show();
  95. photo.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
  96. }
  97. catch (System.InvalidOperationException ex)
  98. {
  99. MessageBox.Show("An error occurred.");
  100. }
  101. }
  102. private void image1_Tap(object sender, GestureEventArgs e)
  103. {
  104. try
  105. {
  106. image.Show();
  107. image.Completed += new EventHandler<PhotoResult>(imageChooserTask_Completed);
  108. }
  109. catch (System.InvalidOperationException ex)
  110. {
  111. MessageBox.Show("An error occurred.");
  112. }
  113. }
  114. }
  115. }