如果我有这样的接口:
public interface IImageService
{
ObservableCollection<PictureModel> RefreshSavedImages();
void PhotoChooserWithCameraServiceShow();
}
他的实现是:
public class ImageService: IImageService
{
public ObservableCollection<PictureModel> RefreshSavedImages()
{
// Refreash images from library
}
public WriteableBitmap StreamToWriteableBitmap(Stream imageStream)
{
WriteableBitmap image = new WriteableBitmap(1024, 768);
image.SetSource(imageStream);
imageStream.Dispose();
return image;
}
public void PhotoChooserWithCameraServiceShow()
{
// PhotoChooserTask get source of image.
}
}
当我在 ViewModel 中实现时:
private readonly IImageService imageService;
public MainViewModel(IImageService imageService)
{
this.imageService = imageService;
}
private void MethodA()
{
// Choose Photo, I edited it and after saved it.
imageService.PhotoChooserWithCameraServiceShow();
// Refreash the library and Bind it in my ItemSource from my ListBox.
PictureList = imageService.RefreshSavedImages();
}
我的问题是我需要先完成这个方法: imageService.PhotoChooserWithCameraServiceShow(); 然后继续 imageService.RefreshSavedImages();
问题是我的程序所做的是在第一个完成之前执行第二个。
我认为可能导致此问题的问题:
从 ViewModel 调用 NavigationService 没有逻辑返回。所以不能:
NavigationService 导航 = 新 NavigationService(); navigation.NavigateTo(new Uri("/Views/SecondPage.xaml", UriKind.Relative));
PhotoChooserWithCameraServiceShow 取自Cimbalino Windows Phone 工具包
谢谢大家和问候!