创建Metro Style应用程序并将其添加到OpenWith上下文菜单中



我愿意创建类似于Windows Photo Viewer的地铁样式应用。

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

预先感谢


非常感谢@filip

我在App.xaml.cs中的OnFileActivated(FileActivatedEventArgs args)中写下了以下代码

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();
        }

但是,我的应用在打开时没有显示任何内容。那么,根据您的说法是什么?

如果您编辑您的package.appxmanifest在"清单编辑器的声明"选项卡中添加文件类型关联 - 您的应用将成为可以打开您指定的文件类型的应用程序之一。然后,您只需要在应用程序类中添加一个覆盖以处理本文所述的文件激活:

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
}

最新更新