简体   繁体   中英

Is it possible to set a subject to the mail app in Windows 8 metro application, if I am using share contract and sharing files?

First of all, I am sharing the content from my windows 8 metro application to another app (for example Mailto app) so:

Now I am sharing files to mailto app using share contract and sharing files from my application,

I wanted to know if: -

  1. Can I set the subject to the mailto app to which I am sharing files as an attachement to that mailto app, if so please let me know how can I do this?

  2. If not, please let me know what is the work around?

As of now, it's not possible.

Windows 8 recently introduced a new API called protocol activation. With Protocol activation, you can launch other windows 8 apps from your application and pass in data. Microsoft worked on Maps app and you can now pass information to the Map app as shown here (URI Scheme for maps application) http://msdn.microsoft.com/en-us/library/windows/apps/jj635237.aspx

See a code walkthrough at http://blog.jerrynixon.com/2012/10/walkthrough-using-windows-8-custom.html

Now, i am sure very soon, you will see some custom parameters for Mail app that you can pass from your app using protocol activation.

Just my 2 cents

不,目前无法做到这一点。

I may not be understanding the question correctly but if all you want to do is have the ability to click the "Share" button on the Charms Bar, then select the "Mail" app and have the ability to populate the subject line shown when the "Mail" app's share fly-out is displayed then you can follow this approach:

private DataTransferManager dataTransferManager; //class member

// put the following code block wherever you need it:

// Register as a share source
if (this.dataTransferManager == null)
{
    this.dataTransferManager = DataTransferManager.GetForCurrentView();
    this.dataTransferManager.DataRequested -= this.OnDataRequested;

    try
    {
        this.dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.OnDataRequested);
    }
    catch 
    { 
    };
}

private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    DataRequestDeferral deferal = request.GetDeferral();

    try
    {
        // this property will set your subject line
        // it will also be shown on the Share fly-out (right below the main 
        // heading that says 'Share'
        request.Data.Properties.Title = GetCustomMailSubjectLine();

        if (string.IsNullOrEmpty(request.Data.Properties.Title))
        {
            request.FailWithDisplayText("An operation failed. Please try again.");
        }
        else
        {
            // this will also be shown on the Share fly-out, right below the 'Title'
            // property set above
            request.Data.Properties.Description = GetMyAppsSharingDesciption();

            // use request.Data.SetDataProvider() if your data needs to be asynchronously retrieved
            // otherwise directly use request.Data.SetData() (or one of the other 
            //methods depending on what you need)

            request.Data.SetDataProvider(StandardDataFormats.Html, RetrieveSharedData);
        }
    }
    finally
    {
        deferal.Complete();
    }
}

private async void RetrieveSharedData(DataProviderRequest request)
{
    DataProviderDeferral deferal = request.GetDeferral();

    try
    {
        // this will set your email's body
        request.SetData(await GetCustomMailBodyAsync());
    }
    finally
    {
        deferal.Complete();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM