0

Windows フォト ビューアーに似たメトロ スタイルのアプリを作成したいと考えています。

そのためには、Openwith コンテキスト メニューにアプリを追加する必要があります。また、Windows エクスプローラーで選択した画像ファイルは、フォト ビューアーで開く必要があります。選択した画像ファイルをパラメーターとしてアプリを開く方法は?

前もって感謝します


どうもありがとう@フィリップ

に次のコードを書きましOnFileActivated(FileActivatedEventArgs args)App.xaml.cs

protected override void OnFileActivated(FileActivatedEventArgs args)
        {
            // TODO: Handle file activation

            // The number of files received is args.Files.Size
            // The first file is args.Files[0].Name
            base.OnFileActivated(args);
            StorageFile file = args.Files[0] as StorageFile;

            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                //rootFrame.SourcePageType = typeof(ImageViewer);

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(ImageViewer), file))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }

しかし、私のアプリは開いても何も表示されません。それで、あなたによると、何が欠陥になる可能性がありますか?

4

1 に答える 1

0

Package.appxmanifest を編集して、マニフェスト エディターの [宣言] タブでファイルの種類の関連付けを追加すると、アプリは、指定したファイルの種類を開くことができるアプリの 1 つになります。この記事で説明されているように、App クラスにオーバーライドを追加して、ファイルのアクティブ化を処理するだけです。

protected override void OnFileActivated(FileActivatedEventArgs args)
{
   // TODO: Handle file activation

   // The number of files received is args.Files.Size
   // The first file is args.Files[0].Name
}
于 2012-11-06T05:55:27.520 に答える