だから私はWP7で次のような非常に単純なことをしようとしています:
MainPageのボタンでカメラが起動します。カメラが正常に写真を撮ったら、その写真をSecondPageに渡して起動します。
これが私のコードです:
MainPageコンストラクター内で、カメラタスクを初期化し、デリゲートを設定します。
camTask.Completed += new EventHandler<PhotoResult>(camTask_Completed);
それから私は実装しましたcamTask_Completed
void camTask_Completed(object sender, PhotoResult e)
{
//throw new NotImplementedException();
img = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));
}
写真を撮ってから「同意する」を押すまで、アプリケーションはエラーなしで実行されます。
例外は言う:
Exception {"Navigation is not allowed when the task is not in the foreground."} System.Exception {System.InvalidOperationException}
私が理解しているのは、メソッド内でSecondPageを起動するべきではないということcamTask_Completed
です。
次に、私の質問は次のとおりです。EventHandlerの結果で別のページを起動するにはどうすればよいですか?
ありがとう
更新:(このサブ質問への回答については、このページのこのコメントを参照してください)
ボタンをクリックした直後に(カメラを起動するために)別のエラーが見つかりました:
それは言った例外を投げます:
"Type 'System.Windows.Media.Transform' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute."
どこでシリアル化できTransform
ますか?
私はグーグルでいくつかの検索をして、これを見つけました:
答えが見つかりました、エラーは実際にもそれを示唆しています:)
[DataContract]
[KnownType(typeof(System.Windows.Media.MatrixTransform))]
この問題は解決できるようですが、これらの行をどこに配置すればよいですか?
これは、画像をSecondPageに渡すためのMainPageのコードimg
ですWriteableBitmap
。
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
var brush = new ImageBrush();
brush.ImageSource = img;
PhoneApplicationService.Current.State["bkg"] = brush;
}
再度、感謝します。