c# - Clipboard content of closed Windows Universal App -


i write c# windows universal app user can copy file clipboard. if app closed clipboard content gets lost. usability horrible if user can lose clipboard content easily. there way make clipboard content of app persistent in other classic windows application?

sample code:

public static void copyfiletoclipboard(storagefile file) {     datapackage dp = new datapackage();     dp.requestedoperation = datapackageoperation.copy;     dp.setstorageitems(new list<storagefile>() { file });     clipboard.setcontent(dp); // not available after app closed     clipboard.flush(); }  public static void copytexttoclipboard(string text) {     datapackage dp = new datapackage();     dp.requestedoperation = datapackageoperation.copy;     dp.settext(text); // available after app closed     clipboard.setcontent(dp);     clipboard.flush(); }  //i have tried copy file app folder first has nothing changed. public async static void cacheandcopyfiletoclipboard(storagefile file) {     datapackage dp = new datapackage();     dp.requestedoperation = datapackageoperation.copy;     var xfile = await applicationdata.current.localfolder.createfileasync(file.name);     await file.copyandreplaceasync(xfile);     dp.setstorageitems(new list<storagefile>() { xfile });     clipboard.setcontent(dp); // not available after app closed     clipboard.flush(); } 

so question how can put file clipboard users can paste if app closed?

edit: seems problem of windows universal apps example if copy picture in windows photo app can paste while photo app running. can not imagine strange behavior should default behavior of apps. looks more bug because see no reason strange behavior.

edit2: new example of problem (thanks joe300 feedback). works strings not storagefile (even if copied local app folder first). reason flush() command not work files? ist there special consider when files used (permissions, ... )?

you'll need add call flush content available after app shuts down.

adds content clipboard , releases datapackage object source app. method allows content remain available after application shuts down.

you should set requestedoperation:

dp.requestedoperation = datapackageoperation.copy; try {     windows.applicationmodel.datatransfer.clipboard.setcontent(dp);     clipboard.flush(); } catch (exception ex) {    // copying data clipboard can potentially fail - example, if application holding clipboard open                   } 

beyond this, there aren't other options manipulating clipboard.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -