所以,下面的代码允许我拍照。然后我显示图片。我的 XAML 绑定到对象的Photo属性Vehicle。它工作正常,直到我进入并尝试再次拍照。然后我得到一个UnauthorizedAccessException. 我在“LocalStorage”中创建文件,所以我认为我不需要特殊权限来在那里写入文件。我不确定是什么导致了错误。
public async Task TakePicture()
    {
        CameraCaptureUI camera = new CameraCaptureUI();
        camera.PhotoSettings.CroppedAspectRatio = new Size(16, 9);
        StorageFile photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
        if (photo != null)
        {
            var targetFolder = ApplicationData.Current.LocalFolder;
            var targetFile = await targetFolder.CreateFileAsync(String.Format
                ("VehiclePhoto{0}.jpg", this.Vehicle.PrimaryKey), CreationCollisionOption.ReplaceExisting);
            if (targetFile != null)
            {
                await photo.MoveAndReplaceAsync(targetFile);
                this.Vehicle.Photo = String.Format("ms-appdata:///local/VehiclePhoto{0}.jpg", this.Vehicle.PrimaryKey);
            }
        }
    }