我有支持ShareTarget将文件上传到云端的应用。当我的应用程序关闭时,一切都很有效(我的意思是关闭 - 不是休眠或类似的东西) - 我选择分享照片,并且每个人都按预期进行。但是当我打开应用程序,然后退出(应用程序在内存中休眠)并尝试在线共享内容
Window.Current.Activate();
我得到了
Exception thrown: 'System.InvalidCastException' in mscorlib.ni.dll
Message "Unable to cast COM object of type 'System.ComponentModel.PropertyChangedEventHandler' to class type 'System.ComponentModel.PropertyChangedEventHandler'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."
然后我的应用程序完全关闭,第二次尝试成功。整个onShareTarget代码:
protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
if (!args.ShareOperation.Data.Contains(
Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
return;
AppShell shell = Window.Current.Content as AppShell;
if (shell == null)
shell = new AppShell();
Window.Current.Content = shell;
shell.AppFrame.Navigate(typeof(ChooseFolderPage), args.ShareOperation);
Window.Current.Activate();
}
任何想法如何解决?