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;
using Microsoft.Phone.Tasks;
namespace ChooserDemo
{
public partial class EmailAddressChooser : PhoneApplicationPage
{
EmailAddressChooserTask eac;
public EmailAddressChooser()
{
InitializeComponent();
eac = new EmailAddressChooserTask();
eac.Completed += new EventHandler(eac_Completed);
}
void eac_Completed(object sender, EmailResult e)
{
if (e.TaskResult == TaskResult.OK)
{
textBox1.Text = e.Email;
}
}
private void btnEmailaddress_Click(object sender, RoutedEventArgs e)
{
eac.Show();
}
}
}
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;
using Microsoft.Phone.Tasks;
namespace ChooserDemo
{
public partial class PhoneNumberChooser : PhoneApplicationPage
{
PhoneNumberChooserTask pnc;
public PhoneNumberChooser()
{
InitializeComponent();
pnc = new PhoneNumberChooserTask();
pnc.Completed += new EventHandler(pnc_Completed);
}
void pnc_Completed(object sender, PhoneNumberResult e)
{
if (e.TaskResult == TaskResult.OK)
{
textBox1.Text = e.PhoneNumber;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
pnc.Show();
}
}
} 4、PhotoChooserTask
PhotoChooserTask是用来选择图片用的,这部分使用上跟CameraCaptureTask是极其相似的,使用时您可以参考CameraCaptuerTask的相关程式码,下面这边来看看执行时的效果
到目前为止的动作都与CameraCaptureTask相同,下面来看看在PhotoChooser中特殊的属性,首先是ShowCamera的属性,ShowCamera的属性是一个布尔型态,当设定为真时,在选择图片的画面中,会出现拍照的按钮,让使用者也可以透过照相机来做为图片的来源,会向下图的样子(您可以看到多出了应用程序栏中并且多了照相的按钮)
接下来是PixelHeight,PixelWidth的属性,这两个属性是让使用者可以裁切原始的图形,比如说,现在应用程式要让使用者设定大头贴,大头贴的尺寸只需要100* 10,这时候过大的图形并没有用处,因此您就可以设定这两个属性,设定之后当使用者选定照片之后会出现裁切的方框,方框会依照您设定的长宽比例做调整,例如下方左图笔者是设定3:8的比例,而右图就是裁切之后的效果了
代码如下:
View Code
View Code
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;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
namespace ChooserDemo
{
public partial class PhotoChooser : PhoneApplicationPage
{
PhotoChooserTask pc;
public PhotoChooser()
{
InitializeComponent();
pc = new PhotoChooserTask();
pc.Completed += new EventHandler(pc_Completed);
}
void pc_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bmpSource = new BitmapImage();
bmpSource.SetSource(e.ChosenPhoto);
image1.Source = bmpSource;
textBlock1.Text = e.OriginalFileName;
}
else
{
image1.Source = null;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//是否裁切相片,並設定裁切後相片的最大高度以及寬度
pc.PixelHeight = 30;
pc.PixelWidth = 80;
//設定是否出現拍照的按鈕(位於Application Bar)
//pc.ShowCamera = true;
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;
using Microsoft.Phone.Tasks;
namespace ChooserDemo
{
public partial class SaveEmailAddress : PhoneApplicationPage
{
SaveEmailAddressTask sea;
public SaveEmailAddress()
{
InitializeComponent();
txtEmail.InputScope = new InputScope()
{
Names = { new InputScopeName() { NameValue = InputScopeNameValue.EmailNameOrAddress } }
};
sea = new SaveEmailAddressTask();
sea.Completed += new EventHandler(sea_Completed);
}
void sea_Completed(object sender, TaskEventArgs e)
{
if (e.TaskResult == TaskResult.OK)
{
//Success
MessageBox.Show("儲存成功!");
}
else
{
MessageBox.Show("儲存失敗!");
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
sea.Email = txtEmail.Text;
sea.Show();
}
}
}
View Code
View Code
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;
using Microsoft.Phone.Tasks;
namespace ChooserDemo
{
public partial class SavePhoneNumber : PhoneApplicationPage
{
SavePhoneNumberTask spn;
public SavePhoneNumber()
{
InitializeComponent();
txtPhoneNo.InputScope = new InputScope()
{
Names = { new InputScopeName() { NameValue = InputScopeNameValue.TelephoneNumber } }
};
spn = new SavePhoneNumberTask();
spn.Completed += new EventHandler(spn_Completed);
}
void spn_Completed(object sender, TaskEventArgs e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show("儲存成功!");
}
else
{
MessageBox.Show("儲存失敗!");
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
spn.PhoneNumber = txtPhoneNo.Text;
spn.Show();
}
}
}