新建一个UserControl,添加到相应位置
相应的后台代码
namespace ImageProcessing{public partial class MessagePhoto : UserControl{ public MessagePhoto(){InitializeComponent();//************让gridbox拉伸*********this.gridBox.Width = Application.Current.Host.Content.ActualWidth;}//获取图像void PictureCaptureTask_Completed(object sender, PhotoResult e){if (e.TaskResult == TaskResult.OK){BitmapImage bmp = new BitmapImage();bmp.SetSource(e.ChosenPhoto);}}//打开相机private void btnCamera_Click(object sender, RoutedEventArgs e){CameraCaptureTask cameraCaptureTask = new CameraCaptureTask();if (cameraCaptureTask != null){cameraCaptureTask.Show();}cameraCaptureTask.Completed += new EventHandler(PictureCaptureTask_Completed);} //打开相册private void btnAlbum_Click(object sender, RoutedEventArgs e){PhotoChooserTask photoChooserTask = new PhotoChooserTask();if (photoChooserTask != null){photoChooserTask.Show();}photoChooserTask.Completed += new EventHandler (PictureCaptureTask_Completed);}}}
主页进行调用
Popup messagebox = new Popup();messagebox.Child = new MessagePhoto();messagebox.IsOpen = true;