0

我愿意创建一个类似于 Windows Photo Viewer 的 Metro 风格应用程序。

为此,我需要在 Openwith 上下文菜单中添加我的应用程序。此外,在 Windows 资源管理器中选择的图像文件应在我的照片查看器中打开。如何以选定的图像文件作为参数打开应用程序?

提前致谢


非常感谢@Filip

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 以在清单编辑器的声明选项卡中添加文件类型关联 - 您的应用将成为可以打开您指定的文件类型的应用之一。然后,您只需向您的 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 回答