【问题标题】: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?如果我使用共享合同和共享文件,是否可以在 Windows 8 Metro 应用程序中为邮件应用程序设置主题?
【发布时间】:2012-10-26 06:14:29
【问题描述】:
首先,我将 Windows 8 Metro 应用程序中的内容共享到另一个应用程序(例如 Mailto 应用程序),因此:
现在我正在使用共享合同将文件共享到 mailto 应用程序并从我的应用程序共享文件,
我想知道:-
我可以将主题设置为我共享文件的 mailto 应用,作为该 mailto 应用的附件吗?如果可以,请告诉我该怎么做?
如果没有,请告诉我解决方法是什么?
【问题讨论】:
标签:
email
microsoft-metro
windows-runtime
winrt-xaml
【解决方案3】:
我可能没有正确理解这个问题,但如果您只想点击超级按钮栏上的“分享”按钮,然后选择“邮件”应用程序并能够填充主题行显示“邮件”应用的共享飞出时显示,然后您可以按照以下方法:
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();
}
}