public MainPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator, IPageDialogService dialogService, IPicture picture ) { //IUnityContainer myContainer = (App.Current as PrismApplication).Container; //_picture= myContainer.Resolve<IPicture>(); // 相依性服務注入的物件 _picture = picture; _dialogService = dialogService; _eventAggregator = eventAggregator; _navigationService = navigationService; // 頁面中綁定的命令 TakePictureCommand = new DelegateCommand(async() => { var fooAction = await _dialogService.DisplayActionSheetAsync("請選擇圖片來源", "取消", null, "相簿", "拍照"); if (fooAction == "相簿") { App.CroppedImage = null; await SelectPicture(); } else if (fooAction == "拍照") { App.CroppedImage = null; await TakePicture(); } else if (fooAction == "取消") { } }); SavePictureCommand = new DelegateCommand(() => { if (App.CroppedImage != null) { _picture.SavePictureToDisk("MyCrop", App.CroppedImage); } }); LoadPictureCommand = new DelegateCommand(() => { App.CroppedImage = _picture.LoadPictureFromDisk("MyCrop"); Stream stream = new MemoryStream(App.CroppedImage); fooLoadImageSource = ImageSource.FromStream(() => stream); }); }