Interaction on desktop Programs (Winform or others) and Metro/modern programs (Windows store app) (open each other, configure read, etc.)

Source: Internet
Author: User

This headline really made me feel the egg hurts. I don't know what to call Microsoft's name-changing maniac.

This is the process by which your desktop program interacts with the Windows Store app.

For some reason, Microsoft's Store app's security sandbox has led to a lot of things that can't be done, so an extra one has been made. NET Desktop Engine to assist, you now need to interact with the two programs in different environments.

First step: In the Desktop app Engine, wake up the store app.

According to MSDN, the simplest approach here is to use the Protocol (URI protocol) to resolve it.

1: Open the package.appxmanifest of the program, add the Protocol in the Declaration

The protocol added to the name is what you want.

For example:bingnews://

can open Bing News

The name is the red part of the front.

Let's try input weipaisuperbar.

After you add the agreement,

Processing of the introduced protocol content in App.xaml.cs

protected override void OnActivated (Iactivatedeventargs args) {    if (args. Kind = = Activationkind.protocol)    {        Protocolactivatedeventargs Protocolargs =           args as Protocolactivatedeventargs;        var rootframe = new Frame ();        Rootframe.navigate (typeof (blogitems), args);        Window.Current.Content = Rootframe;    }    Window.Current.Activate ();}

Turn around and automatically navigate to the Blogitems page.



Now that the app has been started, go to WinForm and write code to try it out.

The startup code is simple, too.
  Process.Start ("Weipaisuperbar://whatever");

  

This solves the problem of starting the store application WinForm.

In the second step, WinForm reads the configuration file for the store app.

Because the security sandbox, so pinch you also don't want to read the store app's root directory, there is no registry permissions, so to interact with external programs please use

Roaming (can roam the data, the user to change the device after the login account can continue to roam back)

Local (only used locally)

It's certainly best to help us roam the data, and we'll use this as an example.


Initialize the configuration file string _name = "Settings.xml"; Windows.Storage.StorageFolder storagefolder = Windows.Storage.ApplicationData.Current.RoamingFolder; Create File var _file = await Storagefolder.createfileasync (_name, Windows.Storage.CreationCollisionOption.ReplaceExisting);

OK, so in the C:\Users\ user name \appdata\local\packages\ program name \roamingstate inside will have settings.xml this file, then read and write is simple

Interaction on desktop Programs (Winform or others) and Metro/modern programs (Windows store app) (open each other, configure read, etc.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.